Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h" // https://github.com/FastLED/FastLED
- #define NEO_PIN PIN_PB1 // or 1 (NeoPixel pin on ATtiny85)
- #define ADC_IN PIN_PB4 // or 4 (ADC2 input pin on ATtiny85)
- #define NEO_COUNT 10 // Number of NePixels connected in a string (could be 10 or 20)
- uint8_t NEO_BRIGHTNESS = 5; // NeoPixel brightness
- uint32_t MIN_RANDOM_NUM = 150; // lower random blink time
- uint32_t MAX_RANDOM_NUM = 1000; // upper random blink time
- // State variables to determine when to start showing NecPixel blinkies
- bool waitForAmberLEDStartup = true;
- bool showNeoPixelBlinkies = false;
- long delayFudgeFactorMS = 1000;
- uint32_t colors[] = {
- 0x00FF0000, // Red
- 0x00FF6666, // Lt. Red
- 0x0000FF00, // Green
- 0x0066FF66, // Lt. Green
- 0x000000FF, // Blue
- 0x0099CCFF, // Lt. Blue
- 0x00FFFFFF, // White
- 0x00FFFF00, // Yellow
- 0x00FFFF99, // Lt. Yellow
- 0x00FF66FF, // Pink
- 0x00FFCCFF // Lt. Pink
- };
- CRGB leds[NEO_COUNT];
- struct Timer{
- bool state;
- uint32_t nextUpdateMillis;
- };
- Timer* timer;
- // ==============================================================================================
- void setup()
- {
- // Set up FastLED
- FastLED.addLeds<WS2812, NEO_PIN, RGB>(leds, NEO_COUNT); // RGB ordering
- FastLED.setBrightness(NEO_BRIGHTNESS);
- timer = new Timer[NEO_COUNT];
- for (size_t i = 0; i < NEO_COUNT; i++)
- {
- timer[i].state = 0; // start with all Neos off, and initial timings
- leds[i] = 0x00000000; // Black
- timer[i].nextUpdateMillis = millis() + random(MIN_RANDOM_NUM, MAX_RANDOM_NUM);
- }
- // if analog input pin 1 is unconnected, random analog
- // noise will cause the call to randomSeed() to generate
- // different seed numbers each time the sketch runs.
- // randomSeed() will then shuffle the random function.
- randomSeed(analogRead(A1));
- }
- // ==============================================================================================
- void loop()
- {
- unsigned long currentTimeMS = millis();
- if ( (currentTimeMS >= (2000)) && (waitForAmberLEDStartup == true) ) {
- waitForAmberLEDStartup = false;
- showNeoPixelBlinkies = true;
- }
- if ( showNeoPixelBlinkies == true ) {
- updateNEOs();
- }
- FastLED.show();
- }
- void updateNEOs() {
- const uint32_t interval = 2;
- static uint32_t last = 0;
- uint32_t now = millis();
- bool dirty = false;
- if (now - last >= interval) {
- last = now;
- for (size_t i = 0; i < NEO_COUNT; i++)
- {
- if (millis() >= timer[i].nextUpdateMillis)
- {
- dirty = true;
- if (timer[i].state)
- {
- leds[i] = 0x00000000; // Black (off)
- }
- else
- {
- leds[i] = colors[random(sizeof(colors) / sizeof(uint32_t))]; // random colour
- }
- timer[i].state = !timer[i].state;
- timer[i].nextUpdateMillis = millis() + random(MIN_RANDOM_NUM, MAX_RANDOM_NUM);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment