I thought this part would be quite straightforward, but having quite a time with the while statement. been at it a while, and out of head scratches.
The way I see this is that line 9 should go to the button loop, which forever calls the ready loop until pin 3 goes low, at which point it should return to he void loop at line 11. In action it just keeps running the ready loop.
I swapped while for if with expected results .. it only tests once and does return to the void loop. What am I missing?
EDIT .. pin 3 is on a momentary pushbutton to ground with a 10K pullup on the pin - it's not a hardware issue.
int x = 0;
int a = 0;
void setup() {
pinMode(3, INPUT); //
Serial.begin(9600, SERIAL_8N1);
}
void loop() {
button();
for (int x = 0; x < 60; x = x + 1) {
Serial.write(0x12);
Serial.write(" ELAPSED SECONDS IN SHOP: ");
if (x < 10) { Serial.write("0"); }
Serial.print(x);
delay(1000);
Serial.write(0x12);
}
}
void ready() {
Serial.write(0x12);
Serial.write("?Ready_");
delay(100);
Serial.write(0x12);
Serial.write("?Ready ");
delay(100);
}
void button() {
a = digitalRead(3);
while (a = HIGH)
{ ready(); }
}
Ah, heck. I had actually tried the double equal because I understood that from the language tutorial, but it didn't work until I also added the second instance of read as per DrDiettrich.
Appreciate the help making it work, but why does the state need to be tested again?
Some may say I like to bang my head against the wall, but I like to know WHY something works, not that it just does.
Learned the 6502 the 'hard' way when Reagan was cracking jokes .. and I was pretty decent - although so far this has been a bit harder, (mostly no time anymore) but it's coming.