Hello
I try to do an automation, but I have difficulties and I turn to you for help. I have two buttons for UP and DOWN, when you press and hold the button UP, the relay for operation is activated and works while the button is held. When you press and hold the DOWN button, the UP relay must be activated for one second and stopped, then the COMPR relay must be activated for one second and stopped, and then the DOWN relay must be activated and remain so until release the button.
I use a translator and I don't know how correct the translation is, for which I apologize.
this is my code
const int BUTTON_UP = 8;
const int BUTTON_DOWN = 9;
const int RELAY_UP = 2;
const int RELAY_DOWN = 3;
const int RELAY_COMPR = 4;
int BUTTONstate_UP = 0;
int BUTTONstate_DOWN = 0;
void setup() {
pinMode(BUTTON_UP, INPUT);
pinMode(BUTTON_DOWN, INPUT);
pinMode(RELAY_UP, OUTPUT);
pinMode(RELAY_DOWN, OUTPUT);
pinMode(RELAY_COMPR, OUTPUT);
}
void loop() {
BUTTONstate_UP = digitalRead(BUTTON_UP);
if (BUTTONstate_UP == HIGH)
{
digitalWrite(RELAY_UP, HIGH);
}
else{
digitalWrite(RELAY_UP, LOW);
}
BUTTONstate_DOWN = digitalRead(BUTTON_DOWN);
if (BUTTONstate_DOWN == HIGH)
{
digitalWrite(RELAY_UP, HIGH);
delay(1000);
digitalWrite(RELAY_UP, LOW);
}
else{
digitalWrite(RELAY_UP, LOW);
}
BUTTONstate_DOWN = digitalRead(BUTTON_DOWN);
if (BUTTONstate_DOWN == HIGH)
{
digitalWrite(RELAY_COMPR, HIGH);
delay(1000);
digitalWrite(RELAY_COMPR, LOW);
}
else{
digitalWrite(RELAY_COMPR, LOW);
}
BUTTONstate_DOWN = digitalRead(BUTTON_DOWN);
if (BUTTONstate_DOWN == HIGH)
{
digitalWrite(RELAY_DOWN, HIGH);
}
else{
digitalWrite(RELAY_DOWN, LOW);
}
}