#include SoftwareSerial mySerial(10, 11); bool serial_mode = false void setup() { mySerial.begin(9600); NSBegin(8, 2) } void loop() { if (serial_mode == false) { d12 = DigitalRead(12) DigitalWrite(13, d12) } while (mySerial.available()) { String s1 = mySerial.readStringUntil(':'); String s2 = mySerial.readStringUntil(';'); if (s1 != NULL && s1.length() > 0 && s2 != NULL && s2.length() > 0) { serial_mode = true PrintLine(s1 + ":" + s2 + ";") process_event(s1, s2); } } while (Serial.available()) { String s1 = Serial.readStringUntil(':'); String s2 = Serial.readStringUntil(';'); if (s1 != NULL && s1.length() > 0 && s2 != NULL && s2.length() > 0) { serial_mode = true PrintLine(s1 + ":" + s2 + ";") process_event(s1, s2); } process_event(s1, s2); } delay(10); } void process_event(String s1, String s2) { if (s1 == "LED" && s2 == "on") { DigitalWrite(13, HIGH) NSSetAllColor(150, 150, 150) NSShow() } if (s1 == "LED" && s2 == "off") { DigitalWrite(13, LOW) NSSetAllColor(0, 0, 0) NSShow() } if (s1 == "brightness") { int b = s2.toInt(); int c = map(b, 0, 100, 0, 255) NSSetAllColor(c, c, c) NSShow() } if (s1 == "color") { if (s2 == "red") NSSetAllColor(255, 0, 0) if (s2 == "green") NSSetAllColor(0, 255, 0) if (s2 == "blue") NSSetAllColor(0, 0, 255) if (s2 == "yellow") NSSetAllColor(255, 255, 0) if (s2 == "orange") NSSetAllColor(255, 127, 0) NSShow() } }