I have made a traffic light simulator:
int RED = 13;
int YELLOW = 12;
int GREEN = 11;
int DELAY_RED = 5000;
int DELAY_YELLOW = 2000;
int DELAY_GREEN = 5000;
void setup(){
pinMode(RED,OUTPUT);
pinMode(YELLOW,OUTPUT);
pinMode(GREEN,OUTPUT);
}
void loop()
{
digitalWrite(RED, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, LOW);
delay(DELAY_RED);
digitalWrite(RED, HIGH);
digitalWrite(YELLOW, HIGH);
digitalWrite(GREEN, LOW);
delay(DELAY_YELLOW);
digitalWrite(RED, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, HIGH);
delay(DELAY_GREEN);
digitalWrite(RED, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(GREEN, LOW);
delay(DELAY_YELLOW);
}
I am using Arduino UNO R3. Now, my question is, how can I end this programme with a KeyboardStroke?
I've done some research, and I found out I don't need a loop, I need a "while" function. So, how can I stop my programme with a KeyboardStroke, and a while loop?
I was thinking of something like this:
While(1) {programme}
If KeyboardStroke(a) then While(2)
Something like that. Is that the right code? How do I change the number in the brackets (1) to (2) ?
Will the KeyboardStroke function work?
Or is there a better way to stop a programme.
So, basicaly, I want to stop a programme with a keyboard stroke, and then to turn it back on with a keyboard stroke.