I am new in Arduino so i need help.... I have a set up with 4 buttons to control 4 lights.
operation:
when Button 1 is pressed and released , light 1 goes ON and OFF after 5 sec, and the same thing for the rest.
But my struggle is when multiple buttons are pressed after another..., like if a button is pressed and while the respective light is ON another button is also pressed, i want the second light to wait for the previous light go OFF before it can turn ON and the same thing for the rest.
OP might want to decide how many button presses do they want to save. Lets say 10. So you'd want to have a way to allow the button presser to press 10 buttons and, at the same time, replay the sequence of button presses. I bet delay will not work, so the OP may want to learn about using millis() for delay instead of dealy(X) but I don't really know if the OP is using delay(), just a guess. Cause there is not any posted code to work with.
So why not help us help you and help us stop making silly guesses and post the well formatted code in code tags, and the schematic, and a image of the project.
Hello
I´ll start with some lines of pseudo code:
for all button in use {
if (button_released) (switch light on AND start timer)
if (timer_triggered) (switch light off AND stop timer)
}
Here you can see the basic functions are requiered.
if(button1State == LOW) // If button is pressing
{
digitalWrite(LED1_PIN, HIGH); // turn on LED1
delay(1000);
}
else {digitalWrite(LED1_PIN, LOW);}
// control LED2 according to the state of button
if(button2State == LOW) // If button is pressing
{
digitalWrite(LED2_PIN, HIGH); // turn on LED2
delay(1000);
}
else {digitalWrite(LED2_PIN, LOW);}
// control LED3 according to the state of button
if(button3State == LOW) // If button is pressing
{
digitalWrite(LED3_PIN, HIGH); // turn on LED1
delay(1000);
}
else {digitalWrite(LED3_PIN, LOW);}
// control LED4 according to the state of button
if(button4State == LOW) // If button is pressing
{
digitalWrite(LED4_PIN, HIGH); // turn on LED1
delay(1000);
}
else { digitalWrite(LED4_PIN, LOW);}
Hello
In next step I recommend to study the IPO principle.
To your task -
Input: read buttons, including deboucing and transition detection
Processing: Analyze button and timer behaiviour and prepare action
Output: Switch light