Skip to content

Instantly share code, notes, and snippets.

@gelicia
Created October 21, 2017 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gelicia/1feb34203cd5fc94b21bfed001181ce0 to your computer and use it in GitHub Desktop.
Save gelicia/1feb34203cd5fc94b21bfed001181ce0 to your computer and use it in GitHub Desktop.
umbrastaff
#include <FastLED.h>
#define SENSOR_PIN 6
#define LED_PIN 3
#define NUM_LEDS 15
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
int mode = 0;
int storeSensorVal = 1;
CRGBPalette16 currentPalette;
TBlendType currentBlending;
CRGBPalette16 modes[6] = { RainbowColors_p, PartyColors_p, CloudColors_p, OceanColors_p, ForestColors_p, LavaColors_p };
int numModes = 6;
void setup() {
Serial.begin(9600);
pinMode(SENSOR_PIN, INPUT);
delay( 3000 ); // power-up safety delay
FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop() {
int sensorVal = digitalRead(SENSOR_PIN);
if (sensorVal == 0 && storeSensorVal == 1) {
mode++;
if (mode == numModes) {
mode = 0;
}
}
storeSensorVal = sensorVal;
currentPalette = modes[mode];
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment