Go Down

Topic: delay prog. execution by waiting for keybord input (Read 1 time) previous topic - next topic


From a newbie:
This should delay program execution until key pressed. However program starts over and over again:

void setup() {
     Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps

int incomingByte = 0;      // for incoming serial data
int NoB=0;  

void loop() {
       Serial.println("start of program");
// suspend prog. execution until keyboard data received
       do {
       } while (NoB=0);
// continue prog. execution e.g. read the incoming byte:
     incomingByte = Serial.read();
     Serial.print("I received: ");
     Serial.println(incomingByte, DEC);

Thanks for any hint


Code: [Select]
while (NoB=0);
This is an assignment statement, not an equality check. Change = to ==.
The art of getting good answers lies in asking good questions.



You could shorten your "wait loop" even to this:
Code: [Select]

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com


Thank you James,
I see the difference between an expert and a newbie!

Go Up