Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define DATA_PIN 0
- #define BUTTON_LEAD 4
- #define NUMBER_OF_MODES 4
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define NUM_LEDS 175
- CRGB leds[NUM_LEDS];
- #define BRIGHTNESS 255
- #define FRAMES_PER_SECOND 120
- //The following constant is the delay between each pixel flash
- const int interval = 25;
- unsigned long previousMillis = millis();
- int mode = 1; //Default mode is one.
- bool buttonState = LOW;
- bool lastButtonState = LOW;
- void setup(){
- pinMode(BUTTON_LEAD, INPUT_PULLUP);
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(BRIGHTNESS);
- }
- uint8_t gHue = 0;
- void loop() {
- switch (mode) {
- case 1:
- sinelon();
- break;
- case 2:
- confetti();
- break;
- case 3:
- juggle();
- break;
- case 4:
- bpm();
- break;
- default:
- mode = 1;
- break;
- }
- FastLED.show();
- EVERY_N_MILLISECONDS( 20 ) { gHue++; }
- }
- /* monitor button press */
- bool buttonListener() {
- bool modeChanged = false;
- buttonState = digitalRead(BUTTON_LEAD);
- if (buttonState != lastButtonState) {
- if (buttonState == LOW) {
- mode++;
- modeChanged = true;
- delay(250); // Debounce delay. I checked the best parameter and 250 was it.
- }
- }
- lastButtonState = buttonState;
- return modeChanged;
- }
- void sinelon() {
- if(buttonListener()) { return; }
- if(millis() - previousMillis >= interval) {
- previousMillis = millis();
- fadeToBlackBy(leds, NUM_LEDS, 20);
- int pos = beatsin16(13,0,NUM_LEDS);
- leds[pos] += CHSV(gHue, 255, 192);
- }
- }
- void confetti() {
- if(buttonListener()) { return; }
- if(millis() - previousMillis >= interval) {
- previousMillis = millis();
- fadeToBlackBy(leds, NUM_LEDS, 10);
- int pos = random16(NUM_LEDS);
- leds[pos] += CHSV( gHue + random8(64), 200, 255);
- }
- }
- void juggle() {
- if(buttonListener()) { return; }
- if(millis() - previousMillis >= interval) {
- previousMillis = millis();
- 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, 255);
- dothue += 32;
- }
- }
- }
- void bpm() {
- if(buttonListener()) { return; }
- if(millis() - previousMillis >= interval) {
- previousMillis = millis();
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = PartyColors_p;
- uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
- for(int i = 0; i < NUM_LEDS; i++) {
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment