I have a program that flashes three ledsLED in sequence indefinitely. How would I be able tocan O program a pushbutton to pause the program in the middle of the code?
Also, how wouldcan I be able to modify the code so that pressing the button a second time would speed up the flashing of the ledLED?
Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.
Here's my code at the moment (sorry that, it's not very clean):
int ledpins[] = {4, 5, 6};
int buttonpin = 3;
int buttonstate = 0;
void setup() {
Serial.begin(9600);
for (int pin=6;pin pin>3;= 6; pin > 3; pin--) {
pinMode(ledpins[pin], OUTPUT);
}
pinMode(buttonpin, INPUT);
}
void loop() {
buttonstate = buttonstate=digitalReaddigitalRead(buttonpin);
if (buttonstate==HIGHbuttonstate == HIGH) {
digitalWrite(ledpins, HIGH);
}
if (buttonstate==LOWbuttonstate == LOW) {
for (int pin = for(int4; pin=4;pin pin<7;< 7; pin++) {
digitalWrite(pin, HIGH);
delay(200);
digitalWrite(pin, LOW);
}
for (int pin = for(int6; pin=6;pin pin>3;> 3; pin--) {
digitalWrite(pin, HIGH);
delay(200);
digitalWrite(pin, LOW);
}
}
}