Add on & off commands + Relay state communication
This commit is contained in:
parent
a995a19211
commit
88a71796a7
1 changed files with 16 additions and 1 deletions
|
@ -10,6 +10,7 @@ byte buttonState[relayCount];
|
||||||
byte lastButtonState[relayCount];
|
byte lastButtonState[relayCount];
|
||||||
|
|
||||||
String receivedCom;
|
String receivedCom;
|
||||||
|
String sentStatus;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
@ -41,11 +42,25 @@ void loop()
|
||||||
{
|
{
|
||||||
receivedCom.replace(String(i), "");
|
receivedCom.replace(String(i), "");
|
||||||
relayState[i] = !relayState[i];
|
relayState[i] = !relayState[i];
|
||||||
Serial.println(i);
|
}
|
||||||
|
|
||||||
|
if (receivedCom == "off")
|
||||||
|
{
|
||||||
|
relayState[i] = LOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receivedCom == "on")
|
||||||
|
{
|
||||||
|
relayState[i] = HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(relayPin[i], relayState[i]);
|
digitalWrite(relayPin[i], relayState[i]);
|
||||||
EEPROM.update(i, relayState[i]);
|
EEPROM.update(i, relayState[i]);
|
||||||
lastButtonState[i] = buttonState[i];
|
lastButtonState[i] = buttonState[i];
|
||||||
|
sentStatus += relayState[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serial.println(sentStatus);
|
||||||
|
sentStatus = "";
|
||||||
|
receivedCom = "";
|
||||||
}
|
}
|
Reference in a new issue