add new patterns

This commit is contained in:
nek0 2021-04-17 00:19:33 +02:00
parent a70dc9ca8e
commit 5e80414b06
2 changed files with 61 additions and 13 deletions

View File

@ -17,13 +17,13 @@ FASTLED_USING_NAMESPACE
#define DATA_PIN 32
//#define CLK_PIN 4
#define LED_TYPE WS2812B
#define COLOR_ORDER BGR
#define LED_TYPE WS2812
#define COLOR_ORDER RGB
#define NUM_LEDS 100
CRGB leds[NUM_LEDS];
define BRIGHTNESS 96
define FRAMES_PER_SECOND 120
#define BRIGHTNESS 96
#define FRAMES_PER_SECOND 120
void setup() {
delay(3000); // 3 second delay for recovery
@ -47,7 +47,7 @@ uint8_t gHue = 0; // rotating "base color" used by many of the patterns
void loop()
{
// Call the current pattern function once, updating the 'leds' array
gPatterns[2]();
gPatterns[gCurrentPatternNumber]();
// send the 'leds' array out to the actual LED strip
FastLED.show();
@ -56,7 +56,7 @@ void loop()
// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
//EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

View File

@ -5,22 +5,25 @@
#define COLOR_ORDER RGB
#define NUM_LEDS 100
#define PIN 32
#define BRIGHTNESS 30
#define BRIGHTNESS 100
#define FPS 120
#define NUM_PATTERNS 4
#define NUM_PATTERNS 7
CRGB leds[NUM_LEDS];
int posx, posy, dx, dy, current_pattern;
bool panelUpFade = true;
typedef void (*PatternList[])();
uint8_t hue = 0;
uint8_t hue = 0, panelBrightness = 0;
CHSV panelColor;
void confetti() {
fadeToBlackBy(leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV(hue + random8(64), 200, 255);
leds[pos] += CHSV(hue + random8(64), 255, 255);
}
void setup_pong() {
@ -55,7 +58,7 @@ void pong() {
fadeToBlackBy(leds, NUM_LEDS, 10);
if (posx < 10 && posy < 10) {
leds[(posy * 10) + posx] += CHSV(hue, 200, 255);
leds[(posy * 10) + posx] += CHSV(hue, 255, 255);
}
}
@ -77,15 +80,57 @@ void raindbowWithGlitter() {
addGlitter(80);
}
void fullPanel() {
if (panelUpFade) {
if (panelBrightness < 255) {
panelBrightness = min(255, panelBrightness + (255 / FPS));
} else {
panelUpFade = false;
}
} else {
if (panelBrightness > 0) {
panelBrightness = max(0, panelBrightness - (255 / FPS));
} else {
panelUpFade = true;
}
}
fill_solid(leds, NUM_LEDS, CRGB(CHSV(hue, 255, panelBrightness)));
}
void scanLineHorz() {
fadeToBlackBy(leds, NUM_LEDS, 10);
for (int i = (posx / 10) % (int)sqrt(NUM_LEDS);
i < NUM_LEDS;
i += (int)sqrt(NUM_LEDS)) {
leds[i] = CRGB(CHSV(hue, 255, 255));
}
posx++;
}
void scanLineVert() {
fadeToBlackBy(leds, NUM_LEDS, 10);
for (int i = (posx / 10) % (int)sqrt(NUM_LEDS) * (int)sqrt(NUM_LEDS);
i < ((posx / 10) % (int)sqrt(NUM_LEDS) * (int)sqrt(NUM_LEDS)) +
(int)sqrt(NUM_LEDS);
i++) {
leds[i] = CRGB(CHSV(hue, 255, 255));
}
posx++;
}
PatternList patterns = {
confetti,
pong,
rainbow,
raindbowWithGlitter
raindbowWithGlitter,
fullPanel,
scanLineHorz,
scanLineVert
};
void nextPattern(){
current_pattern = (current_pattern + 1) % NUM_PATTERNS;
panelUpFade = true;
}
void setup() {
@ -108,5 +153,8 @@ void loop() {
FastLED.delay(1000/FPS * 2);
EVERY_N_MILLISECONDS(20) {hue++;}
EVERY_N_SECONDS(10) {nextPattern();}
EVERY_N_SECONDS(10) {
setup_pong();
nextPattern();
}
}