Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************************************************
- // beat8 example with random freeze experiment for Erin.
- // Open the serial monitor to see the random times.
- //
- // -Marc Miller, March 2017
- //***************************************************************
- #include "FastLED.h"
- #define LED_TYPE LPD8806
- #define DATA_PIN 11
- #define CLOCK_PIN 13
- #define NUM_LEDS 32
- #define COLOR_ORDER GRB
- #define BRIGHTNESS 128
- CRGB leds[NUM_LEDS];
- uint8_t moveSpeed = 6; // Higher value moves pixel faster.
- uint8_t fadeRate = 30; // Use lower value to give a fading tail.
- const uint16_t startDelay = 5000; // Number of milliseconds before re-start
- int analogSeedPin = 20; // Any un-used analog pin. Used for generating seed for random16.
- int analogSeedPinB = 21; // Any un-used analog pin. Used for generating seed for random16.
- uint8_t gHue = 0; // Used to cycle through rainbow.
- unsigned long timeDelay = startDelay;
- unsigned long freezeTime = 10000000; // Just something really large to prevent triggering on startup
- //---------------------------------------------------------------
- void setup()
- {
- Serial.begin(115200); // Allows serial monitor output (check baud rate)
- delay(3000); // 3 second delay
- FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(BRIGHTNESS);
- }
- //---------------------------------------------------------------
- void loop()
- {
- EVERY_N_MILLISECONDS( 50 ) { gHue++; } // Slowly cycle through the rainbow
- static boolean frozen = true; // [Initially set true!]
- if (frozen) { // [FROZEN]
- EVERY_N_MILLISECONDS(500){
- static boolean getReady = false;
- getReady = !getReady;
- if (getReady) {
- leds[0] = CHSV(42,255,255);
- } else {
- leds[0] = CRGB::Black;
- }
- }
- // This if statement delays the start of the moving pixel.
- // It could be changed so it would be true after a "start" button was been pressed.
- if (millis() > timeDelay) {
- frozen = false; // toggle frozen variable
- uint16_t seed = random16_get_seed();
- seed = seed + analogRead(analogSeedPin) + analogRead(analogSeedPinB); // create a random seed
- random16_add_entropy(seed);
- seed = random16_get_seed();
- freezeTime = random16(3000,23000); // random number of milliseconds before freezing
- Serial.print("freezeTime = "); Serial.print(freezeTime/1000.0); Serial.println(" seconds.");
- freezeTime = millis() + freezeTime;
- }
- }//end_of_FROZEN
- if (!frozen) { // [IS NOT FROZEN]
- beat8_tail(); // Subroutine to move the pixel!
- }
- FastLED.show(); // Display the pixels.
- // Check to see if the random freeze time has been reached.
- // If true then stop the animation.
- if (millis() > freezeTime){
- frozen = true; // toggle frozen variable
- timeDelay = millis() + startDelay; // set new start time
- freezeTime = millis() + 1000000; // To prevent re-triggering
- }
- }//end main loop
- //===============================================================
- void beat8_tail()
- {
- EVERY_N_MILLISECONDS( 5 ) {
- fadeToBlackBy( leds, NUM_LEDS, fadeRate); // Fade out pixels.
- }
- uint16_t pos = beat8(moveSpeed) % NUM_LEDS; // modulo the position to be within NUM_LEDS
- leds[pos] = CHSV( gHue, 200, 255);
- }
Add Comment
Please, Sign In to add comment