hello, i am trying to use a switch on node-red to turn an led on, on the Arduino i am not sure if im doing it right. i am getting data back from node red on the serial monitor but i cant seem to do anything with that data.
please help thanks.
i am using an Arduino MKRWIFI1010
while (mqttClient.available()) {
Serial.print((char)mqttClient.read());
Serial.println();
int state = (int)mqttClient.read();
if(state == 1){
digitalWrite(0, HIGH);
}
if(state == 2){
digitalWrite(0, LOW);
}
}
You do know that the first read() consumes the character you see in the Serial Monitor, so the state code sees only a potential second character, don't you?