Hi everyone,
I am pretty much brand new to arduino and coding and i am having some trouble with LEDs and i am hoping you guys can help me:)
I have connected 3 LEDs in a series and got as far with the programming so that now when i press the button all three LEDs come on and stay on until i let go of the switch.
What i want to do is:
press button once, first led comes on
press button again, second led comes on
press button third time, third led comes on
all LEDs stay on for 6 seconds before turning off from the last time the button was pressed.
I really hope u guys can help me, i will be waiting,
Thanks!
Here is the coding i have so far:
const int buttonPin = 2; // pushbutton pin
const int ledPin1 = 13; // LED pin
const int ledPin2 = 12;
const int ledPin3 = 8;
int buttonState = 0; //reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
if (buttonState == HIGH) { // check if the pushbutton is pressed.
digitalWrite(ledPin1, LOW);
}
if (buttonState == HIGH) {
digitalWrite(ledPin2, LOW);
}
if (buttonState == HIGH) {
digitalWrite(ledPin3, LOW);
}
else {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
}
}