113 lines
1.8 KiB
C++
113 lines
1.8 KiB
C++
#include <Arduino.h>
|
|
#include <FastLED.h>
|
|
|
|
#define LED_TYPE WS2812B
|
|
#define COLOR_ORDER RGB
|
|
#define NUM_LEDS 100
|
|
#define PIN 32
|
|
#define BRIGHTNESS 30
|
|
#define FPS 120
|
|
#define NUM_PATTERNS 4
|
|
|
|
CRGB leds[NUM_LEDS];
|
|
|
|
int posx, posy, dx, dy, current_pattern;
|
|
|
|
typedef void (*PatternList[])();
|
|
|
|
uint8_t hue = 0;
|
|
|
|
void confetti() {
|
|
fadeToBlackBy(leds, NUM_LEDS, 10);
|
|
int pos = random16(NUM_LEDS);
|
|
leds[pos] += CHSV(hue + random8(64), 200, 255);
|
|
}
|
|
|
|
void setup_pong() {
|
|
posx = random(0, 9);
|
|
posy = random(0, 10);
|
|
|
|
dx = random(0, 1);
|
|
if (dx == 0) {
|
|
dx = -1;
|
|
}
|
|
dy = random(0, 1);
|
|
if (dy == 0) {
|
|
dy = -1;
|
|
}
|
|
}
|
|
|
|
void pong() {
|
|
int nposx = posx + dx;
|
|
if (nposx < 0 || nposx > 9) {
|
|
dx = dx * -1;
|
|
nposx = posx + dx;
|
|
}
|
|
posx = nposx;
|
|
|
|
int nposy = posy + dy;
|
|
if (nposy < 0 || nposy > 10) {
|
|
dy = dy * -1;
|
|
nposy = posy + dy;
|
|
}
|
|
posy = nposy;
|
|
|
|
fadeToBlackBy(leds, NUM_LEDS, 10);
|
|
|
|
if (posx < 10 && posy < 10) {
|
|
leds[(posy * 10) + posx] += CHSV(hue, 200, 255);
|
|
}
|
|
}
|
|
|
|
void rainbow()
|
|
{
|
|
// FastLED's built-in rainbow generator
|
|
fill_rainbow(leds, NUM_LEDS, hue, 7);
|
|
}
|
|
|
|
void addGlitter( fract8 chanceOfGlitter)
|
|
{
|
|
if( random8() < chanceOfGlitter) {
|
|
leds[ random16(NUM_LEDS) ] += CRGB::White;
|
|
}
|
|
}
|
|
|
|
void raindbowWithGlitter() {
|
|
rainbow();
|
|
addGlitter(80);
|
|
}
|
|
|
|
PatternList patterns = {
|
|
confetti,
|
|
pong,
|
|
rainbow,
|
|
raindbowWithGlitter
|
|
};
|
|
|
|
void nextPattern(){
|
|
current_pattern = (current_pattern + 1) % NUM_PATTERNS;
|
|
}
|
|
|
|
void setup() {
|
|
FastLED.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
|
|
|
|
FastLED.setBrightness(BRIGHTNESS);
|
|
|
|
FastLED.showColor(CRGB(0, 0, 0));
|
|
|
|
setup_pong();
|
|
}
|
|
|
|
void loop() {
|
|
//confetti();
|
|
//pong();
|
|
|
|
patterns[current_pattern]();
|
|
|
|
FastLED.show();
|
|
FastLED.delay(1000/FPS * 2);
|
|
|
|
EVERY_N_MILLISECONDS(20) {hue++;}
|
|
EVERY_N_SECONDS(10) {nextPattern();}
|
|
}
|