Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define NUM_LEDS 30
- #define DATA_PIN 6
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- #define FRAMES_PER_SECOND 120
- CRGB leds[NUM_LEDS];
- uint8_t ButtonPins[] = {0,2};
- uint8_t pinCount = 2;
- uint8_t *myPointer;
- void setup() {
- FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(50);
- for(uint8_t x = 0; x<pinCount; x++)
- {
- pinMode(ButtonPins[x], INPUT_PULLUP);
- }
- Serial.begin(9600);
- }
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = { rainbow, confetti, sinelon, juggle, bpm };
- 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() {
- for(uint8_t x =0; x<pinCount; x++)
- {
- ButtonPins[x] = digitalRead(x);
- }
- for(uint8_t pin = 0; pin < pinCount; pin++)
- {
- myPointer = &ButtonPins[pin];
- if (*myPointer == 0)
- {
- gPatterns[pin]();
- }
- }
- FastLED.show();
- Serial.print(*myPointer);
- Serial.println();
- FastLED.delay(1000/FRAMES_PER_SECOND);
- EVERY_N_MILLISECONDS( 20 ) { gHue++; }
- }
- void rainbow()
- {
- // FastLED's built-in rainbow generator
- fill_rainbow( leds, NUM_LEDS, gHue, 5);
- }
- 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 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), 200, 255);
- }
- void sinelon()
- {
- // a colored dot sweeping back and forth, with fading trails
- fadeToBlackBy( leds, NUM_LEDS, 20);
- int pos = beatsin16( 13, 0, NUM_LEDS-1 );
- leds[pos] += CHSV( gHue, 255, 192);
- }
- void bpm()
- {
- // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = PartyColors_p;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- 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-1 )] |= CHSV(dothue, 200, 255);
- dothue += 32;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement