Hi All
I have only just started to learn the Arduino 3 days ago and I am kind of struggling with task I have set myself.
Using an Arduino Leonardo I have 1 relay and 3 buttons to control the relay, I can get the buttons to work intermittently for the require times but the button presses do not always work, I am unsure as to how to use the if, else statements in the code, I have had a good look at many examples and I am sorry to say I have thoroughly confused myself :o
Any Help, pointers would be greatly appreciated.
int buttonPin(2);
int buttonPin2(4);
int buttonPin3(5);
int buttonPress=0;
int buttonPress2=0;
int buttonPress3=0;
int RelayPin(3);
void setup()
{
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(RelayPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
buttonPress = digitalRead(buttonPin);
if(buttonPress == 1){
delay (50);
buttonPress = digitalRead(buttonPin);
if(buttonPress == 0){
digitalWrite(RelayPin, HIGH);
delay (1500);
digitalWrite(RelayPin, LOW);
}}
else{
delay(100);
}
{
buttonPress2 = digitalRead(buttonPin2);
if(buttonPress2 == 1){
delay (50);
buttonPress2 = digitalRead(buttonPin2);
if(buttonPress2 == 0){
digitalWrite(RelayPin, HIGH);
delay (500);
digitalWrite(RelayPin, LOW);
}}
else{
delay(100);
}}
{
buttonPress3 = digitalRead(buttonPin3);
if(buttonPress3 == 1){
delay (50);
buttonPress3 = digitalRead(buttonPin3);
if(buttonPress3 == 0){
digitalWrite(RelayPin, HIGH);
delay (1000);
digitalWrite(RelayPin, LOW);
}}
else{
delay(100);
}}
}