/*************************************************************************************** Ten LEDs Lighting for One Knob Boards Code Made for DAC Power Button Including LEDs Animation for DAC Status Information Author: Corentin Mornet Project: echo DAC Date: January 18th 2017 Inspired by: http://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ http://www.tweaking4all.com/forums/topic/fastleds-fun-with-a-broken-switchcase/ ***************************************************************************************/ #include "FastLED.h" #define NUM_LEDS 10 // Number of LEDs used #define PIN_LEDS 6 // Pin used for LEDs data #define SWITCH 4 // Pin used for On/Off Switch #define RPI_CONNECTED 2 // Pin used for NAS connection feedback from RaspberryPi CRGB leds[NUM_LEDS]; const int speedDelay = 50; const int startupColorR = 0xFF; // Start-up color, Red LED const int startupColorG = 0xFF; // Start-up color, Green LED const int startupColorB = 0xFF; // Start-up color, Blue LED const int connectedColorR = 0xFF; // Connected color, Red LED const int connectedColorG = 0xFF; // Connected color, Green LED const int connectedColorB = 0xFF; // Connected color, Blue LED const float increment = 0.006; // Modifies animation speed const float steadyBrightness = 1.8*PI; // Actual brightness used in functions; 1.5*PI is 0% and 2.5*PI is 100% brightness const int animation = 4; // Select animation when NAS connection is established; 0: Twinkle, 1: ColorWipe, 2: TheaterChase, 3: RunningLights, 4: Cylon int steps = 0; boolean connectedNAS = false; void setup() { FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); pinMode(SWITCH,INPUT); // Input from selector switch pinMode(RPI_CONNECTED,INPUT); // Input from RaspberryPi setAll(0x00, 0x00, 0x00); // Starts with all turned off LEDs } void loop() { connectedNAS = digitalRead(RPI_CONNECTED); if (digitalRead(SWITCH) == HIGH) { if (steps == 0) // STEP 1 : progressive start of the start-up color lighting { startLighting(startupColorR, startupColorG, startupColorB); delay(20*speedDelay); // 1s delay steps = 1; } else { if (steps == 1) // STEP 2 : LEDs animation while RapberryPi Starts and connects to NAS server { if (connectedNAS == false) { if (animation == 0) { twinkleLighting(connectedColorR, connectedColorG, connectedColorB, 10, true); } else { if (animation == 1) { colorWipeLighting(connectedColorR, connectedColorG, connectedColorB); colorWipeLighting(0x00, 0x00, 0x00); } else { if (animation == 2) { theaterChaseLighting(connectedColorR, connectedColorG, connectedColorB); } else { if (animation == 3) { runningLightsLighting(connectedColorR, connectedColorG, connectedColorB); } else { if (animation == 4) { cylonLighting(connectedColorR, connectedColorG, connectedColorB, 1); } } } } } } else { setAll(0x00, 0x00, 0x00); delay(20*speedDelay); // 1s delay steps = 2; } } else { if (steps == 2) // STEP 3 : Animation of the connected color lighting depending on animation selected in constant { if (connectedNAS == true) { startLighting(connectedColorR, connectedColorG, connectedColorB); delay(20*speedDelay); // 1s delay steps = 3; } else { steps = 1; } } else { if (steps == 3) // STEP 4 :steady connected color lighting while ready { if (connectedNAS == true) { steadyLighting(connectedColorR, connectedColorG, connectedColorB); } else { stopLighting(connectedColorR, connectedColorG, connectedColorB); delay(20*speedDelay); // 1s delay steps = 1; } } } } } } else { setAll(0x00, 0x00, 0x00); steps = 0; } }