Pages: [1]   Go Down
Author Topic: delay prog. execution by waiting for keybord input  (Read 721 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 {
        delay(200);
        NoB=Serial.available();
        } 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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
while (NoB=0);
This is an assignment statement, not an equality check. Change = to ==.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

as I said: from a newbie

Thank you!
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 63
Posts: 6049
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could shorten your "wait loop" even to this:
Code:
while(Serial.available()==0);
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: