Basically, how do I modify my code listed below to turn ON each of the three LEDs one at a time in a repetitive sequence while keeping the push-button pressed?
- Red (3 sec),
- Yellow (1 sec), and
- Green (3 sec).
I'm trying to get all three LEDs to turn OFF when the push button is released.
The code I wrote that doesn't allow me to achieve what I'm trying to do (I'm not sure where I went wrong):
#define Button_Pin 2 //Push Button Pin
#define LED_Pin_1 11 //Red LED
#define LED_Pin_2 10 //Yellow LED
#define LED_Pin_3 9 //Green LED
byte Button_State;
void setup() {
pinMode(Button_Pin, INPUT);
pinMode(LED_Pin_1, OUTPUT);
pinMode(LED_Pin_2, OUTPUT);
pinMode(LED_Pin_3, OUTPUT);
Serial.begin(9600);
Serial.println("Design Part B - Digital I-O Control");
delay(1000);
}
void loop() {
Button_State = digitalRead(Button_Pin);
Serial.print("Button State: ");
Serial.print(Button_State);
if (Button_State == 1){
digitalWrite(LED_Pin_1, HIGH);
delay(3000); //Wait for 3 Secs
digitalWrite(LED_Pin_2, HIGH);
delay(1000); //Waits for 1 Sec
digitalWrite(LED_Pin_3, HIGH);
delay(3000);
Serial.println(" --> Button Pressed --> LED ON");
}
else{
digitalWrite(LED_Pin_1, LOW);
digitalWrite(LED_Pin_2, LOW);
digitalWrite(LED_Pin_3, LOW);
Serial.println(" Button is Released --> LED OFF");
}
}
if (Button_State == 1){
block .... think about what it does and how long it takes to do it ... then examine the blinkWithoutDelay example sketch in the Arfuino IDE