void serial_input()
void serial_input() {
while (Serial1.available()) {
cmd += char(Serial1.read()); // read avaialbe bytes into dfd string
}
if (cmd.substring(0, 3) == "R1:") { // does the substring = R1:
String relay1_cmd = cmd.substring(3, cmd.length()); // read the cmd into relay1_cmd string variable
if (relay1_cmd == "ON") { // if true then turn on relay 1
digitalWrite(relay1, HIGH); // set the digital pin high
} else { // if false then run this statement and set the digital pin low
digitalWrite(relay1, LOW);
}
}
if (cmd.substring(0, 3) == "R2:") { // does the substring = R2:
String relay2_cmd = cmd.substring(3, cmd.length()); // read the cmd into relay2_cmd string variable
if (relay2_cmd == "ON") { // if true then turn on relay 2
digitalWrite(relay2, HIGH); // set the digital pin high
} else { // if false then run this statement and set the digital pin low
digitalWrite(relay2, LOW);
}
}
}Last updated