// constants that won't change:
const byte button_pump = 7;
const byte pump_relais_pin = 5;
// variables that will change
bool pump_state = LOW; // turns on (HIGH) or off (LOW) the realis
bool last_button_pump_state; // previous state of button pump
bool current_button_pump_state; // current state of button pump
void setup() {
pinMode(button_pump, INPUT_PULLUP);
pinMode(pump_relais_pin, OUTPUT);
current_button_pump_state = digitalRead(button_pump);
}
void loop() {
last_button_pump_state = current_button_pump_state;
current_button_pump_state = digitalRead(button_pump);
if(last_button_pump_state == HIGH && current_button_pump_state == LOW) {
if (pump_state == LOW) {
pump_state = HIGH;
} else {
pump_state = LOW;
}
digitalWrite(pump_relais_pin, pump_state);
delay(200);
while(!digitalRead(button_pump));
}
}
// https://www.youtube.com/watch?v=ZoaUlquC6x8&ab_channel=RoboticsBack-End