OK, so far I have shown you what you need, and what not to do, and never dos and just bad things that we tend not to do as programmers. Now I'm going to so you a program side-by-side Arduino vs eclipse using ANSI C.
Arduino | eclipse |
---|---|
/* C-3436A * * C. Harrison Aug 30, 2014 Creation * */ #include "C3436A.h" void setup(){ void modes(); Serial.begin(19200); Serial.println("C-3436A awake"); void init(); } void loop(){ int i; // check for input: while( Serial.available()) { char data = Serial.read(); if( data == '!') { char cmd = Serial.read(); char dat = Serial.read(); char eol = Serial.read(); if( cmd = 1 ) { // panel light ;} if( dat = 0 ) { digitalWrite( dial_light, LOW); } if( dat = 1 ) { digitalWrite( dial_light, HIGH); } }} // read all the data for( i= 1; i < 6; i++ ) { frac[i] = digitalRead( F[i]); hund[i] = digitalRead( H[i]); } pwr = digitalRead( powerpin ); // calulate the values: ftest, Htest; int ftest, htest, ftest0, htest0, pwr, pwr0; ftest = decode_F(calc_F()); htest = decode_H(calc_H()); if( ftest != ftest0 or htest != htest0 or pwr != pwr0 ) { //send message to RSS swap(); } else { ; } // Do Nothing }} int decode_H( int data ){ int code[][2] = {{13,0},{9,108},{11,109},{5,110}, {27,111},{16,112},{30,113},{2,114}, {23,115},{8,116},{28,117},{1,118}, {7,119},{4,120},{24,121},{20,122}, {6,123},{18,124},{17,125},{10,126}}; for( int i= 0; i < 22; i++ ) { if( data == code[i][0]) { return code[i][1]; } }} int decode_F( int data ){ int code[] = {20, 5, 8, 2, 16, 4, 1, 9, 10, 18 }; for( int i= 0; i < 10; i++ ) { if( data == code[i]) { return i; } }} int calc_F(){ int temp = ( F[22] + (F[21]*2) + (F[20]*4) + (F[8]*8) + (F[7]*16)); return( temp ); } int calc_H(){ int temp = ( H[19] + (H[18]*2) + (H[17]*4) + (H[5]*8) + (H[4]*16)); return( temp ); } void swap(){ for( int i = 1; i < 6; i++ ) { frac0[i] = frac[i]; hund0[i] = hund[i]; } ftest0 = ftest; htest0 = htest; pwr0 = pwr; } void modes(){ pinMode( F[1], INPUT_PULLUP); pinMode( F[2], INPUT_PULLUP); pinMode( F[3], INPUT_PULLUP); pinMode( F[4], INPUT_PULLUP); pinMode( F[5], INPUT_PULLUP); // hundreds array pinMode(H[1], INPUT_PULLUP); pinMode(H[2], INPUT_PULLUP); pinMode(H[3], INPUT_PULLUP); pinMode(H[4], INPUT_PULLUP); pinMode(H[5], INPUT_PULLUP); // Now we have to assign the power switch pin pinMode( powerpin, INPUT_PULLUP); // Now we have to assign the digital output pins pinMode(dial_light, OUTPUT); } // we need to read the first time so while in loop the test will not fail. // read all the pins and put then in arrays void init(){ int i; for( i=1; i< 7; i++){ frac0[i] = digitalRead(F[i]); hund0[i] = digitalRead(H[i]); } ftest0 = decode_F(calc_F()); htest0 = decode_H(calc_H()); pwr = digitalRead(powerpin); } | * C-3436A.c ** C. Harrison Aug 30, 2014 Creation * July 3, 2018 Re-Creation from arduino source * */ #include "C3436A.h" #include "C3436A.subs.c" void main( ){ init(); //one time call to do some housekeeping // the next two lines deal with arduino serial library Serial.begin(19200); Serial.println("C-3436A awake"); do{ int i; // check for input: while( Serial.available()) { char data = Serial.read(); if( data == '!') { char cmd = Serial.read(); char dat = Serial.read(); char eol = Serial.read(); if( cmd = 1 ) { // panel light } if( dat = 0 ) { digitalWrite( dial_light, LOW); } if( dat = 1 ) { digitalWrite( dial_light, HIGH); }} // read all the data for( i= 1; i < 6; i++ ) { frac[i] = digitalRead( F[i]); hund[i] = digitalRead( H[i]); } pwr = digitalRead( powerpin ); // calulate the values:ftest, Htest; int ftest, htest, ftest0, htest0, pwr, pwr0; ftest = decode_F(calc_F()); htest = decode_H(calc_H()); if( ftest != ftest0 or htest != htest0 or pwr != pwr0 ) { //send message to RSS swap(); } else { ; }}(while TRUE ); // This is a forever loop with out an exit } // Do Nothing return; } NOTES:
|
/* C-3436A.h * * C. Harrison Aug 21, 2014 Creation * */ // we need to list the digital input pins: // Pin defs // please note: arrays F[] & H[] are being indexed 1-5 int F[]= { 0, 22, 23, 24, 25, 26 }; int H[]= { 0, 30, 31, 32, 33, 34 }; int powerpin = 20; int dial_light = 40; // now we need the variables & arrays int frac[6]; int hund[6]; int frac0[6]; int hund0[6]; int pwr, pwr0; int ftest, ftest0; int htest, htest0; | /* C-3436A.subs.c * * C. Harrison Aug 30, 2014 Creation * July 3, 2018 Re-Creation from arduino source * */ int decode_H( int data ){ int code[][2] = {{13,0},{9,108},{11,109},{5,110}, {27,111},{16,112},{30,113},{2,114}, {23,115},{8,116},{28,117},{1,118}, {7,119},{4,120},{24,121},{20,122}, {6,123},{18,124},{17,125},{10,126}}; for( int i= 0; i < 22; i++ ) { if( data == code[i][0]) { return code[i][1]; }}} int decode_F( int data ){ int code[] = {20, 5, 8, 2, 16, 4, 1, 9, 10, 18 }; for( int i= 0; i < 10; i++ ) { if( data == code[i]) { return i; }}} int calc_F(){ int temp = ( F[22] + (F[21]*2) + (F[20]*4) + (F[8]*8) + (F[7]*16)); return( temp ); } int calc_H(){ int temp = ( H[19] + (H[18]*2) + (H[17]*4) + (H[5]*8) + (H[4]*16)); return( temp ); } void swap(){ for( int i = 1; i < 6; i++ ) { frac0[i] = frac[i]; hund0[i] = hund[i]; } ftest0 = ftest; htest0 = htest; pwr0 = pwr; } void init(){ // we need to read the first time so while in the loop the test will not fail. // read all the pins and put them in arrays int i; for( i=1; i< 7; i++){ frac0[i] = digitalRead(F[i]); hund0[i] = digitalRead(H[i]); } ftest0 = decode_F(calc_F()); htest0 = decode_H(calc_H()); pwr = digitalRead(powerpin); } |
/* * C-3436A.h * * C. Harrison Aug 30, 2014 Creation * July 3, 2018 Re-Creation from arduino source * */
#define TRUE 1; #include "include/pins.h" #include "include/modes.h" | |
/* C-3436A.subs.h * * C. Harrison Aug 30, 2014 Creation * July 3, 2018 Re-Creation from arduino source * * int calc_F(); int calc_H(); int decode_F( int data ); int decode_H( int data ); void init(); void swap(); | |
/* * pins.h * * C. Harrison Aug 21, 2014 Creation * July 3, 2018 Re-Creation from arduino source * (https://www.hackster.io/phoenixcomm/nexgen-flight-simulator-radio-interface-5a1f52 ) */ // we need to list the digital input pins:
// Pin defs // please note: arrays F[] & H[] are being indexed 1-5 int F[]= { 0, 22, 23, 24, 25, 26 }; int H[]= { 0, 30, 31, 32, 33, 34 };
int powerpin = 20; int dial_light = 40; | |
/* * modes.h * * C. Harrison Aug 21, 2014 Creation * July 3, 2018 Re-Creation from arduino source */ void modes(){ // units array pinMode( F[1], INPUT_PULLUP); pinMode( F[2], INPUT_PULLUP); pinMode( F[3], INPUT_PULLUP); pinMode( F[4], INPUT_PULLUP); pinMode( F[5], INPUT_PULLUP); // hundreds array pinMode(H[1], INPUT_PULLUP); pinMode(H[2], INPUT_PULLUP); pinMode(H[3], INPUT_PULLUP); pinMode(H[4], INPUT_PULLUP); pinMode(H[5], INPUT_PULLUP); // Now we have to assign the power switch pin pinMode( powerpin, INPUT_PULLUP); // Now we have to assign the digital output pins pinMode(dial_light, OUTPUT); } |
Revisions:
- Purists, please don't jump down my throat. I broke a general rule on header files that it should not contain executable code. The header file modes.h has a function modes() this function should go into C-3436A.subs.c and then called placed in the top of the function init without the function wrapper. [Wednesday, July 4, 2018 5:40:21 PM GMT]
- This is a letter that I just (a few hours ago to the folks at Element14. This letter/note discusses the <pre> tag and how it does not work as advertised!
You all know how I barely tolerate this really crappy editor with all its stupid quirks (me being nice!) You should do everybody a favor and JUST EMBRACE HTML5 with CSS (just like eBay !) Like your stupid reason forbidding <style> tags (local tags CAN NOT BE HACKED!) so that now we can use classes!; Yes you could inject malicious code with this external stylesheet! Duh so don't allow this: "<link rel="stylesheet" type="text/css" href="mystyle.css">" (local tags CAN NOT BE HACKED!))! But you guys tossed out the bathwater, the baby went with it. LOL!
But whats wrong with this:
"<style>
Arial10 {font-family: 'arial'; font-size: 10px;}
</style>"
useage: <div class="Arial10" style="....
But this one is OFF THE CHART~!
First Offical reference the lowly <pre>...</pre> tag!
https://developer.mozilla.org/en-US/docs/Web/HTML...Text in a pre element is displayed in a fixed-width font, and it preserves both spaces and line breaks.
---------- REAL LIFE case in point:
"NexGen: Software Development: arduino sketch & eclipse on Linux. Part 3"
---------- WAS:/*
* C-3436A.subs.h
*
* C. Harrison Aug 30, 2014 Creation
* July 3, 2018 Re-Creation from arduino source
*
*/
int calc_F();
int calc_H();
int decode_F( int data );
int decode_H( int data );
void init();
void swap();----- GOT -train wreck this is the source!
<p><span style="font-family: 'andale mono', times; font-size: 8pt;">/*<br /> * C-3436A.subs.h</span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;"> *<br /> * C. Harrison Aug 30, 2014 Creation</span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;"> * July 3, 2018 Re-Creation from arduino source</span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;"> *<br /> */<br /></span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;">int calc_F();</span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;">int calc_H();</span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;">int decode_F( int data );</span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;">int decode_H( int data );</span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;">void init();</span></p>
<p><span style="font-family: 'andale mono', times; font-size: 8pt;">void swap();</span></p>
<p style="color: #000000;"><span style="font-family: 'andale mono', times; font-size: 8pt;"></span></p>
---- FIXED This is better.
<pre><span style="font-family: 'andale mono', times; font-size: 8pt;">/*<br /> * C-3436A.subs.h<br /> *<br /> * C. Harrison Aug 30, 2014 Creation<br /> * July 3, 2018 Re-Creation from arduino source</span><br /> *<br /> */<br /><br />int calc_F();<br />int calc_H();<br />int decode_F( int data );<br />int decode_H( int data );<br />void init()void swap();<br /><br /><br /></span></pre>
---- prolog I have spent many an hour last night on the 3rd when by all rights I should be in the pub for it is now the 4th of July (Brits see ref 1776). Last night with too many brews, I have come to this conclusion: That even after I put together a blog in Blue Fish Editor, I know that when I paste it into your editor something WILL BRAKE!! Please for G-d's sake and everybody's sanity GET OVER IT embraces HTML5 and CSS. Thanks for the quality time. Now I have to get the Champaign in the fridge for this eve.
Top Comments