-
-
Save marmilicious/39bcaf9a7844dabd2881da6d82e971ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*************************************************************** | |
// Example for Kyle Bostick for this post: | |
// https://plus.google.com/107012178390358476390/posts/7fUz4nN9tPb | |
// | |
// Marc Miller, Nov 2018 | |
//*************************************************************** | |
#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 255 | |
CRGB leds[NUM_LEDS]; | |
String setEffect = "Red Green White Loop"; //set current effect | |
int animationspeed = 50; //starting speed | |
//--------------------------------------------------------------- | |
void setup() { | |
Serial.begin(115200); // Allows serial monitor output (check your baud rate) | |
delay(2000); // Startup delay | |
FastLED.addLeds<LED_TYPE,DATA_PIN,CLOCK_PIN,COLOR_ORDER>(leds, NUM_LEDS); // ***For strips using Clock. | |
//FastLED.addLeds<LED_TYPE,DATA_PIN>(leds, NUM_LEDS); // ***For Clock-less strips. | |
FastLED.setBrightness(BRIGHTNESS); | |
} | |
//--------------------------------------------------------------- | |
void loop() { | |
if (setEffect == "Red Green White Loop") { | |
//Print out animationspeed to check the value. | |
Serial.print("Animation speed: "); Serial.println(animationspeed); | |
//Adjust speed of function based on the value of animationspeed | |
uint8_t delayValue = map ( animationspeed, 0, 150, 5, 255 ); | |
for(int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = CRGB(255, 0, 0); | |
FastLED.show(); | |
delay(delayValue); | |
} | |
for(int i = (NUM_LEDS)-1; i >= 0; i--) { | |
leds[i] = CRGB(0, 255, 0); | |
FastLED.show(); | |
delay(delayValue); | |
} | |
for(int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = CRGB(255, 255, 255); | |
FastLED.show(); | |
delay(delayValue); | |
} | |
for(int i = (NUM_LEDS)-1; i >= 0; i--) { | |
leds[i] = CRGB(0, 255, 0); | |
FastLED.show(); | |
delay(delayValue); | |
} | |
}//end "Red Green White Loop" | |
//FOR TESTING -- simulated a change of animationspeed | |
//Doesn't actually run every three seconds due to the use of | |
//blocking delay() in the function above, but still works fine | |
//for simulating a change. | |
EVERY_N_SECONDS(3) { | |
animationspeed = random8(0, 150); //pick new random animation speed | |
Serial.println(" **New animationspeed picked**"); | |
} | |
}//end_main_loop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment