/* * RGB LED State Management Demo - Barduino * Fab Academy 2026 - Week 4: Embedded Programming * Shivangi Pande | Fab Lab Barcelona * * Demonstrates that hardware holds its last state: * RGB LEDs don't turn off automatically. * You must explicitly set them to LOW / off. * * Uses the onboard Neopixel RGB LED (pin 38) * via the ESP32 neopixelWrite() function. * * neopixelWrite(pin, R, G, B) — values 0-255 */ // ---- Pin definitions ---- #define RGB_PIN 38 #define LED_PIN 48 // ---- Colour definitions (R, G, B) ---- // Maya's Mirror palette: warm white → teal → pink #define WARM_R 255 #define WARM_G 180 #define WARM_B 100 #define TEAL_R 0 #define TEAL_G 200 #define TEAL_B 180 #define PINK_R 255 #define PINK_G 100 #define PINK_B 150 void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(115200); Serial.println("RGB LED State Demo"); Serial.println("Watch: LED holds colour until explicitly turned off!"); Serial.println("---"); } void loop() { // ---- Warm white (Stage 1: live face) ---- Serial.println("Stage 1: Warm white"); neopixelWrite(RGB_PIN, WARM_R, WARM_G, WARM_B); delay(2000); // ---- EXPLICITLY turn off ---- Serial.println(" → Turning OFF (0,0,0)"); neopixelWrite(RGB_PIN, 0, 0, 0); delay(500); // ---- Teal (Stage 2: dissolve) ---- Serial.println("Stage 2: Teal"); neopixelWrite(RGB_PIN, TEAL_R, TEAL_G, TEAL_B); delay(2000); // ---- EXPLICITLY turn off ---- Serial.println(" → Turning OFF (0,0,0)"); neopixelWrite(RGB_PIN, 0, 0, 0); delay(500); // ---- Pink (Stage 3: botanical art) ---- Serial.println("Stage 3: Pink"); neopixelWrite(RGB_PIN, PINK_R, PINK_G, PINK_B); delay(2000); // ---- EXPLICITLY turn off ---- Serial.println(" → Turning OFF (0,0,0)"); neopixelWrite(RGB_PIN, 0, 0, 0); delay(500); // ---- Demo: what happens if you DON'T turn off? ---- Serial.println("Demo: Setting RED and NOT turning off..."); neopixelWrite(RGB_PIN, 255, 0, 0); delay(3000); // The LED stays red even through the next iteration! // This is the key lesson: hardware holds state. // Uncomment the next line to see the difference: // neopixelWrite(RGB_PIN, 0, 0, 0); Serial.println(" (LED is still red — hardware holds state!)"); Serial.println("---"); delay(2000); // Clean up for next loop neopixelWrite(RGB_PIN, 0, 0, 0); delay(1000); }