Skip to content

Instantly share code, notes, and snippets.

@slurrybowl
Created September 23, 2017 18:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slurrybowl/e5f46229d877c3b98934d7b870b1d60d to your computer and use it in GitHub Desktop.
Save slurrybowl/e5f46229d877c3b98934d7b870b1d60d to your computer and use it in GitHub Desktop.
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define DATA_PIN 4
//#define CLK_PIN 4
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 240
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 95
#define FRAMES_PER_SECOND 120
#include "Button.h" // Include Button library
const int buttonPin = 6; // Set digital pin used with debounced pushbutton
Button myButton(buttonPin, true, true, 50); // Declare the butto
void setup() {
delay(3000); // 3 second delay for recovery
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}
// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
//SimplePatternList gPatterns = { rainbow,juggle_Bchill, rainbowuniform, rainbowWEIRD, rainbowWithGlitter, confetti_GB, confetti, juggle, juggle_B, juggle_R, juggle_G, sinelon };
SimplePatternList gPatterns = { juggle_B_less,juggle_B_more,juggle_B_lots,juggle_Bsteady, confetti_GB, juggle_G, juggle_R };
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
void loop()
{
// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();
// send the 'leds' array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND);
// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
//EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
readbutton(); // check for button press
}
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}
void rainbowuniform()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 2);
}
void rainbowWEIRD()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 30);
}
void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16(13,0,NUM_LEDS);
leds[pos] += CHSV( gHue, 255, 192);
}
void confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 20, 250);
}
void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}
void addGlitter( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}
void juggle_R() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 5;
for( int i = 0; i < 8; i++) {
leds[beatsin16(i+1,0,NUM_LEDS)] |= CHSV(dothue, 200, 100);
//dothue += 32;
}
}
void juggle_G() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 200);
byte dothue = 96;
for( int i = 0; i < 8; i++) {
leds[beatsin16(i+1,0,NUM_LEDS)] |= CHSV(dothue, 200, 100);
//dothue += 32;
}
}
void juggle_B_less() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 240);
byte dothue = 160;
for( int i = 0; i < 8; i++) {
leds[beatsin16(i+1,0,NUM_LEDS)] |= CHSV(dothue, 200, 100);
//dothue += 32;
}
}
void juggle_B_more() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 100);
byte dothue = 160;
for( int i = 0; i < 8; i++) {
leds[beatsin16(i+1,0,NUM_LEDS)] |= CHSV(dothue, 200, 100);
//dothue += 32;
}
}
void juggle_B_lots() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 10);
byte dothue = 160;
for( int i = 0; i < 8; i++) {
leds[beatsin16(i+1,0,NUM_LEDS)] |= CHSV(dothue, 200, 100);
//dothue += 32;
}
}
void juggle_Bsteady() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 1);
byte dothue = 160;
for( int i = 0; i < 240; i++) {
leds[beatsin16(i+200,0,NUM_LEDS)] |= CHSV(dothue, 200, 55);
//dothue += 32;
}
}
void juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for( int i = 0; i < 8; i++) {
leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 100);
dothue += 32;
}
}
void confetti_GB()
{
// random colored speckles, Green and Blue hues only
// Green = 96, Blue = 160
uint8_t p = 30; // What percentage of the time to make speckles. [Range 0-100]
fadeToBlackBy( leds, NUM_LEDS, 10);
if (random8(100) < p) {
int pos = random16(NUM_LEDS);
uint8_t hue = random8(2); // randomly chooses a 0 or 1
if (hue == 0) {
hue = random8(92,111); // pick a hue somewhere in the green zone
} else {
hue = random8(156,165); // pick a hue somewhere in the blue zone
}
leds[pos] += CHSV( hue, random8(200,240), 100);
}
}//end confetti_GB
//BUTTON STUFF
//---------Function to read the button and do something----------
void readbutton() {
myButton.read();
if(myButton.wasPressed()) {
nextPattern(); // Change to the next pattern
}
}//end_readbutton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment