So I started this small project with a LED Matrix.
My goal is to make a waving flag animation on this matrix.
I am just having a lot of trouble with it and can't figure out how to proceed further.
This is an 8x8 matrix where I want the top half to be blue and the bottom half to be yellow.
And so making it waving flag animation. on the matrix.
At this moment this is the code I am using:
#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 64
#define BRIGHTNESS 100
#define PULSE_SPEED 1000
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
fill_solid(leds, NUM_LEDS, CRGB::Black); // Turn off all LEDs initially
}
void loop() {
int pulsePosition = millis() / PULSE_SPEED % 8;
fill_solid(leds, NUM_LEDS, CRGB::Black);
for (int i = 0; i < NUM_LEDS; i++) {
if (i < 32) {
if (i % 8 >= pulsePosition && i % 8 < pulsePosition + 4) {
leds[i] = CRGB(0, 0, 255); // Blue color
}
} else {
if (i % 8 >= pulsePosition && i % 8 < pulsePosition + 4) {
leds[i] = CRGB(255, 255, 0); // Yellow color
}
}
}
FastLED.show();
}
That's what I don't know but to explain it further. That is flows as a wave. To there would be a peak brightness( lets say ) 100 and it would at a decent speed down till 10 and up. Making it look like its waving. So there would be a few peaks while the rest goes down and up.
On a similar project, "waving" the flag was attempted in two ways, both methods iterate through the columns:
Use "empty" (non-colored) rows above and below the flag, first raise column y+1, then y+0, then y-1.
Use color intensity: all pixels at 191 (of 255). column x = 191, x+1 = 255, x-1 = 127
Memory usage became an issue with 512 pixels but 8x8 will fit easily. PROGMEM allowed some movement, but the remaining memory made pixel changes slow. (link to similar project for reference).