I'm not proffessional in arduino coding,and i have an question about sketch. I need code to control relay with push buttons. I have 3 push buttons 3 leds and 2 relays. When 1 button push then select first led if twice push then select second led. When push second button once then select first relay,if twice push then select second relay,and in the end start button to start all this commands an then lights third led. Pls Help! this is my code:
int button1=2;
int button2=3;
int button3=4;
int relay1=8;
int relay2=9;
int led=5;
int led2=6;
int led3=7;
int button1State=0;
int button2State=0;
int button3State=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(button1, INPUT_PULLUP);
pinMode(button2,INPUT_PULLUP);
pinMode(button3,INPUT_PULLUP):
pinMode(relay1, OUTPUT);
digitalWrite(relay1, HIGH);
pinMode(relay2,OUTPUT);
digitalWrite(relay2, HIGH);
pinMode(led,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
button1State = digitalRead(button1);//when once click turn led
if(button1State==HIGH){
digitalWrite(led,HIGH);
delay(wait);
if(button1State==HIGH){ //when clicked twice then turn on led 2, but i dont know how to do it
digitalWrite(led2,HIGH);
delay(wait)
}
}
if (button2State== HIGH){
digitalWrite(relay1,HIGH);
delay(wait);
if(button2State==HIGH){ //when clicked twice turn on second relay but i dont know how to do this
digitalWrite(relay2,HIGH);
delay(wait);
}
if(button2State==HIGH){
digitalWrite(relay1&&relay2,HIGH);
delay(wait);
}
}
//and click start i dont kknow how to do this :((
//when select led then circuits run for 10 sec,if led 2 select then circuit runs for 20 sec
}