#include #define PIN_R D5 #define PIN_G D6 #define PIN_B D7 #define MASK_DATA_PIN D8 #define MASK_LEDS 6 #define EYES_SPEED 10 // in ms #define EYES_HUE 95 #define EYES_BRIGTHNESS 180 #define EYES_SATURATION 255 #define MOUTH_SPEED 20 // in ms #define MOUTH_HUE 180 #define MOUTH_BRIGTHNESS 180 #define MOUTH_SATURATION 255 #define BACKGROUND_SPEED 1000 // in ms // breathing = 0 uint8_t eyesMode = 0; // Define the array of leds CRGB maskLeds[MASK_LEDS]; uint8_t hue = 0; void setup() { Serial.begin(115200); FastLED.addLeds(maskLeds, MASK_LEDS); setupRGB(); Serial.println("Started"); } void loop() { eyesLoop(); mouthLoop(); blinkRGB(); } void breathing(CRGB * leds, uint8_t start, uint8_t end, uint8_t hue, uint8_t saturation, uint8_t brightness) { for (uint8_t i = start; i <= end; i++) { maskLeds[i] = CHSV(hue, saturation, brightness); } FastLED.show(); } void eyesLoop(){ static uint32_t timer = 0; static uint8_t hue = EYES_HUE; static uint8_t brightness = 0; static uint8_t saturation = EYES_SATURATION; static bool breathingIncreasing = true; if(millis() - timer < EYES_SPEED){ return; } timer = millis(); if(eyesMode == 0){ breathing(maskLeds, 0, 2, hue, saturation, brightness); if(breathingIncreasing) { if(brightness < EYES_BRIGTHNESS) { brightness++; } else { breathingIncreasing = false; } } else { if(brightness > 0) { brightness--; } else { breathingIncreasing = true; } } } } void mouthLoop(){ static uint32_t timer = 0; static uint8_t hue = MOUTH_HUE; static uint8_t brightness = 0; static uint8_t saturation = MOUTH_SATURATION; static bool breathingIncreasing = true; if(millis() - timer < MOUTH_SPEED){ return; } timer = millis(); if(eyesMode == 0){ breathing(maskLeds, 3, 5, hue, saturation, brightness); if(breathingIncreasing) { if(brightness < MOUTH_BRIGTHNESS) { brightness++; } else { breathingIncreasing = false; } } else { if(brightness > 0) { brightness--; } else { breathingIncreasing = true; } } } } void setupRGB(){ pinMode(PIN_R, OUTPUT); pinMode(PIN_G, OUTPUT); pinMode(PIN_B, OUTPUT); digitalWrite(PIN_R, LOW); digitalWrite(PIN_G, LOW); digitalWrite(PIN_B, LOW); } void blinkRGB(){ static uint32_t timer = 0; static uint8_t cycle = 0; if(millis() - timer < BACKGROUND_SPEED){ return; } timer = millis(); if(cycle == 0){ digitalWrite(PIN_R, HIGH); digitalWrite(PIN_G, LOW); digitalWrite(PIN_B, LOW); cycle++; }else if(cycle == 1){ digitalWrite(PIN_R, LOW); digitalWrite(PIN_G, HIGH); digitalWrite(PIN_B, LOW); cycle++; } else { digitalWrite(PIN_R, LOW); digitalWrite(PIN_G, LOW); digitalWrite(PIN_B, HIGH); cycle = 0; } }