I see you've made several posts, but did not use code tags for your program code. Please read Nick Gammon's two posts at the top of this Forum for the proper way to post code. You'll likely get more responses if you do.
I'm not exactly sure what you're trying to do. Is this close?
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
char val;
if (Serial.available() > 0) {
val = tolower(Serial.read()); // in case the enter upper case
switch (val) {
case 'a':
digitalWrite(13, HIGH);
Serial.println("ledon");
break;
case 'b':
digitalWrite(13, LOW);
Serial.println("ledoffon");
break;
case 'c':
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
break;
default:
break;
}
}
// here is where i would use d to turn off the while loop for c
}
youknowj2:
i can turn on the loop by sending c. i would like to send d to turn it off... here is my code..
In simple terms, that is not possible. A WHILE loop continues until it completes. You need to use an IF and rely on the repetition of the loop() function to cause the iterations. That way your code can also receive the next instruction and respond to it.
Yes that worked. Thanks. Except I had to add the 1 after the Serial's. I have to send d a few times sometimes to get it to turn off. I was tempted to use a goto which everywhere I looked says its not reccomended. I even tried to use a do while loop but couldn't get it to work either.