// Made for RP2040 #include #include SoftwareSerial mySerial(D8, D9); // RX, TX #define NEOPOWERPIN 11 // Provides voltage for the built-in NeoPixel #define NEOPIXELPIN 12 // Datapin for the the built-in NeoPixel #define NUMPIXELS 1 //Amount of NeoPixels Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXELPIN, NEO_RGB + NEO_KHZ800); const uint8_t my_address = 1; // Network address const uint8_t control_address = 0; // Network address of the "host" const char message_ending = '\n'; bool light_on = false; uint32_t led_color = pixels.Color(255,255,255); bool ignore_message = false; void setup() { pinMode(NEOPOWERPIN, OUTPUT); // initialize digital pin NEOPOWERPIN as an output. digitalWrite(NEOPOWERPIN, HIGH); // Power for the NeoPixel mySerial.begin(9600); //Serial.begin(9600); // for debugging pixels.begin(); } // message: void loop() { if (mySerial.available()) { byte received = mySerial.read(); //Serial.write(received); if (received == message_ending) { ignore_message = false; return; } if (ignore_message) { return; } if (received == my_address) { // There is a message for us while(!mySerial.available()){ // Assume / hope the message will continue.. delay(10); } if (mySerial.read() == control_address) { while(!mySerial.available()){ // Assume / hope the message will continue.. delay(10); } // And it's from the "host", now act on it: switch (mySerial.read()) { case 'o': light_on = true; break; case 'f': light_on = false; break; case 0: led_color = pixels.Color(100,100,100); break; case 1: led_color = pixels.Color(120,10,150); break; case 2: led_color = pixels.Color(155,100,10); break; case 3: led_color = pixels.Color(20,80,120); break; case 4: led_color = pixels.Color(100,90,120); break; case 5: led_color = pixels.Color(255,255,255); break; default: mySerial.println("Not correct command"); break; } if (light_on) { pixels.clear(); pixels.setPixelColor(0, led_color); pixels.show(); } else { pixels.clear(); pixels.show(); } } } else { // The message is meant for someone else ignore_message = true; } } }