From 5e80414b06336a2443fe1e7cc664e8461be79488 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 17 Apr 2021 00:19:33 +0200 Subject: [PATCH] add new patterns --- code/DemoReel100/DemoReel100.ino | 12 +++---- code/Pentasquare/src/main.cpp | 62 ++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/code/DemoReel100/DemoReel100.ino b/code/DemoReel100/DemoReel100.ino index 8e8e9b4..8eda2db 100644 --- a/code/DemoReel100/DemoReel100.ino +++ b/code/DemoReel100/DemoReel100.ino @@ -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])) diff --git a/code/Pentasquare/src/main.cpp b/code/Pentasquare/src/main.cpp index 226c799..e443df8 100644 --- a/code/Pentasquare/src/main.cpp +++ b/code/Pentasquare/src/main.cpp @@ -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(); + } }