Hi, I am trying to program a skill stop function but can not get it working. I have 3 LEDs that i have programmed to go back and forth ( i.e. from 11 to 12 to 13 to 12 and loop back to 11) and what I want is when i push button 3 the LED will stop running and stop at the position when the button was pushed. I don't know what I am doing wrong here, is there someone who can help me out here?
My setup is:
3 LED
2 Pushbuttons
The program:
const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int LedPin11 = 11;
const int LedPin12 = 12;
const int LedPin13 = 13;
boolean Led11Status = LOW;
boolean Led12Status = LOW;
boolean Led13Status = LOW;
void setup() {
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(LedPin11, OUTPUT);
pinMode(LedPin12, OUTPUT);
pinMode(LedPin13, OUTPUT);
}
void loop(){
if(digitalRead(buttonPin2)==LOW && digitalRead(buttonPin3)==HIGH)
{
digitalWrite(LedPin11, HIGH);
Led11Status = HIGH;
delay(100);
digitalWrite(LedPin11, LOW);
Led11Status = LOW;
digitalWrite(LedPin12, HIGH);
Led12Status = HIGH;
delay(100);
digitalWrite(LedPin12, LOW);
Led12Status = LOW;
digitalWrite(LedPin13, HIGH);
Led13Status = HIGH;
delay(100);
digitalWrite(LedPin13, LOW);
Led13Status = LOW;
digitalWrite(LedPin12, HIGH);
Led12Status = HIGH;
delay(100);
digitalWrite(LedPin12, LOW);
Led12Status = LOW;
}
else if(digitalRead(buttonPin2)==LOW && digitalRead(buttonPin3)==LOW)
{
if (Led11Status)
{
digitalWrite(LedPin11, HIGH);
digitalWrite(LedPin12, LOW);
digitalWrite(LedPin13, LOW);
}
else if (Led12Status)
{
digitalWrite(LedPin12, HIGH);
digitalWrite(LedPin11, LOW);
digitalWrite(LedPin13, LOW);
}
else if (Led13Status)
{
digitalWrite(LedPin13, HIGH);
digitalWrite(LedPin11, LOW);
digitalWrite(LedPin12, LOW);
}
}
}