Go Down

Topic: delay prog. execution by waiting for keybord input (Read 987 times) 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 ==.


James C4S

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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131