I am new to arduino, so I'm hoping that the solution to my problem is just a command that I haven't learned yet. My project consists of three buttons, which control three actions. Currently I have successfully made button one control action one, button two control action two, and button three control action three, which is what I want. However, once one button has been pressed and action one begins, if any other button is pressed then the program doesn't notice it. Ideally I'd like it so that you could press all three buttons at once and have all three actions happen at the same time. Is there an easy way (or any way) to do this? Currently I'm just using a simple loop consisting of various if and else statements.
However, once one button has been pressed and action one begins, if any other button is pressed then the program doesn't notice it.
Why not? Is your code using delay()?
Ideally I'd like it so that you could press all three buttons at once and have all three actions happen at the same time. Is there an easy way (or any way) to do this?
There's not even a hard way. The Arduino is single threaded. However, depending on what the things are, the Arduino can appear to do them all at once. As long as you banish delay() from your repertoire.
Currently I'm just using a simple loop consisting of various if and else statements.
However, once one button has been pressed and action one begins, if any other button is pressed then the program doesn't notice it.
Why not? Is your code using delay()?
Yes, I'm using delay because I want each action to go on for three seconds...here's the code for one of the actions (it's basically the same for all three just changing which val to look at)
void loop()
{
valPU= digitalRead (PUswitch); //read the PUswitch value
valLL = digitalRead (LLswitch);//read the LLswitch value
valEYS = digitalRead (EYSswitch); //read the EYSswitch value
if (valPU == LOW) {//check if PU input value is HIGH button released
runPUswitchon = 0; //don't run PUswitchon
Serial.print ("value of PUswitch is");
Serial.println (valPU); //displays the value in the serial monitor
}
else {
runPUswitchon=1;
Serial.print ("value of PUswitch is");
Serial.print (valPU);
digitalWrite (Relay1,HIGH);
Serial.print ("Relay1 is on");
delay (3000);
digitalWrite (Relay1,LOW);
}