04-03-2024, 12:18 PM
(04-02-2024, 09:52 PM)admin Wrote: your code function is when digital input trigger, Toggle relay.
you can replace this code:
digitalWrite(Relay1, !digitalRead(Relay1));
use if .... else ... for ON/OFF relay.
Thank you Sir,
SOLVED in this way :
void ScanKey1() {
KEY_NUM1 = 1; // Key1 unpressed
if (digitalRead(Key1) == LOW) { // Key1 Pressed
delay(20);
if (digitalRead(Key1) == LOW) {
KEY_NUM1 = 0; // if digitalRead(Key1 == low)
digitalWrite(Relay1, HIGH); // Relay1 is Turned ON
} else { // if Key1 is turned OFF (Key4 open)
digitalWrite(Relay1, LOW); // Rela1 is turned OFF
}
}
}