// here i found some info regarding debug print using macro / and compiler switches // http://forum.arduino.cc/index.php?topic=256308.0 // now i combine it with a toggle menu variable // KLL 17.09.2014 //Sketch uses 6,374 bytes (22%) of program storage space. Maximum is 28,672 bytes. //Global variables use 206 bytes (8%) of dynamic memory, leaving 2,354 bytes for local variables. Maximum is 2,560 bytes. // shows: //HALLO WORLD setup //HALLO WORLD loop, type d[ENTER] to switch OFF //HALLO WORLD loop, type d[ENTER] to switch OFF .... // until you send "d"[ENTER] //#define DEBUG // if compiler switch OFF see //Sketch uses 6,182 bytes (21%) of program storage space. Maximum is 28,672 bytes. //Global variables use 206 bytes (8%) of dynamic memory, leaving 2,354 bytes for local variables. Maximum is 2,560 bytes. #define DEBUG #ifdef DEBUG #define db(t,x) if(t) { Serial.print(x); } #define dbln(t,x) if(t) { Serial.println(x); } #else #define db(t,x) // define empty, so macro does nothing #define dbln(t,x) #endif boolean debugp = true; // variables dump to screen for diag const long ser0bd = 115200; // 300, 1200 good, 2400, 9600 good, 14400, 19200 good, 28800, 38400 good, 57600 setpoint not good, 115200 good //String inputstring = ""; // a string to hold incoming data from the PC int serloop = 0, serloopend = 5001; // only after serloopend cycles check for USB income, because its slow char inChar; // operator input for menu operation const char mline[]="_______________________________"; //___________________________________________________________________________________ void serial_setup() { Serial.begin(ser0bd); //set baud rate for the hardware serial port_0 #if defined(__PIC32MX__) #else while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only // not work? } // inputstring.reserve(20); //set aside some bytes for receiving data from the PC but seems to work also for longer strings?? #endif } //___________________________________________________________________________________ void one_char_operator_input_NOWAIT() { serloop = serloop + 1; // for check on USB if (serloop == serloopend) { serloop = 0; //reset and check ( after serloopend cycles ) // by sending one byte from PC Terminal select job from menu if (Serial.available() > 0) { // USB terminal interrupt NO WAIT and only check SERLOOPEND loops // read the first incoming byte: inChar = (char)Serial.read(); // take a byte while (Serial.available() > 0) { Serial.read(); } // clean the rest } // end avail } // after xxx loops check on serial available } // end //___________________________________________________________________________________ void operator_HMI() { one_char_operator_input_NOWAIT(); switch (inChar) { #ifdef DEBUG case 'd': //a menu entry //Serial.write(inByte); debugp = !debugp; //toggle debug break; #endif case ' ': //[space] #ifdef DEBUG Serial.println(F(" d: diag toggle")); #endif // here more menu ... Serial.println(mline); Serial.print (F("select: ")); break; } // switch inChar = 0; } //___________________________________________________________________________________ void setup() { serial_setup(); dbln(debugp,F("HALLO WORLD setup")); } //___________________________________________________________________________________ void loop() { operator_HMI(); dbln(debugp,F("HALLO WORLD loop, type d[ENTER] to switch OFF ")); }