#include <FastLED.h>
#include <OneButton.h>
#define NUM_LEDS 113
#define LED_PIN 2
#define BTN_PIN 3
CRGB leds[NUM_LEDS];
uint8_t patternCounter = 0;
// Push button connected between pin 7 and GND (no resistor required)
OneButton btn = OneButton(BTN_PIN, true, true);
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(50);
Serial.begin(57600);
btn.attachClick(nextPattern);
}
void loop() {
switch (patternCounter) {
case 0:
Effect1();
break;
case 1:
Effect2();
break;
case 2:
Effect3();
break;
}
FastLED.show();
btn.tick();
}
void nextPattern() {
patternCounter = (patternCounter + 1) % 3; // Change the number after the % to the number of patterns you have
}
//------- Put your patterns below -------//
void Effect1() {
uint16_t posBeat = beatsin16(5, 0, NUM_LEDS - 1, 0, 0);
uint16_t posBeat2 = beatsin16(20, 0, NUM_LEDS - 1, 0, 0);
uint16_t posBeat3 = beatsin16(5, 0, NUM_LEDS - 1, 0, 32767);
uint16_t posBeat4 = beatsin16(20, 0, NUM_LEDS - 1, 0, 32767);
// Wave for LED color
uint8_t colBeat = beatsin8(45, 0, 70, 0, 0);
leds[(posBeat + posBeat2) / 2] = CHSV(colBeat, 255, 255);
leds[(posBeat3 + posBeat4) / 2] = CHSV(colBeat, 255, 255);
fadeToBlackBy(leds, NUM_LEDS, 0);
}
void Effect2() {
uint16_t beatA = beatsin16(10, 0, 255);
uint16_t beatB = beatsin16(5, 0, 255);
fill_rainbow(leds, NUM_LEDS, (beatA+beatB)/2, 2);
}
void Effect3() {
uint16_t sinBeat = beatsin16(5, 0, NUM_LEDS - 1, 0, 0);
uint16_t sinBeat2 = beatsin16(5, 0, NUM_LEDS - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(5, 0, NUM_LEDS - 1, 0, 43690);
uint16_t sinBeat4 = beatsin16(5, 0, NUM_LEDS - 1, 0, 63690);
leds[sinBeat] = CRGB::Purple;
leds[sinBeat2] = CRGB::Red;
leds[sinBeat3] = CRGB::Crimson;
leds[sinBeat4] = CRGB::Pink;
fadeToBlackBy(leds, NUM_LEDS, 0);
}