Ok, I have started a new topic since my old one was getting messy and hard to understand. This code has been driving me nuts and I am only on my 3rd day of programing so I don't understand much more than the commands I am using in this code.
Basically This code flashes a green led under normal operation,
when my "push button" (I am actually using a switch) is LOW I want the Green LED to flash non stop
When I flip my switch and my "button input" goes HIGH I want to light my red LED for 2 seconds, than
have the RED go out and than flash my yellow LED non stop until my switch is flipped and my "push button input returns to LOW.
At that point it will go back to the normal operation of flashing GREEN until the switch is flipped again.
Now, What I am getting is when my switch goes HIGH, My RED LED comes on for 2 seconds, than goes out and my yellow light flashes ONCE... Than the RED LED comes on again for 2 seconds, than the YELLOW flashes again and so on until the switch goes LOW.
I would like this RED LED to ONLY come on once when the switch is flipped, than just flash the YELLOW LED until the "push button" input goes low.
Could someone please give me an understanding of how this could be done?
const int redPin = 10; //RED LED ON PIN 10
const int yelPin = 11; //YELLOW LED ON 11
const int greenPin = 12; //GREEN LED ON 12
const int pushbutton = 2; //SWITCH FOR BUTTON ON PIN 2
int buttonState1 = 0;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(pushbutton, INPUT); //SETS OUTPUTS
pinMode(yelPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
buttonState1 = digitalRead(pushbutton);
if (buttonState1 == HIGH) {{
digitalWrite(redPin, HIGH);
delay(1500); // THIS IS THE OPERATION I ONLY WANT TO RUN ONCE
digitalWrite(redPin, LOW);
digitalWrite(yelPin, HIGH);
delay(538); // THIS IS THE OPERATION I WANT TO LOOP WHILE BUTTON IS HIGH
digitalWrite(yelPin, LOW);
delay(538);
}}
else {
digitalWrite(greenPin, HIGH);
delay(500); //BUTTON LOW, FLASH GREEN
digitalWrite(greenPin, LOW);
delay(500);
}}