LED Matrix waving flag animation

Hello!

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();
}

Could someone help me with this?

that's easy

#include <FastLED.h>

constexpr size_t NUM_ROWS = 8;
constexpr size_t NUM_COLS = 8;
constexpr size_t NUM_LEDS = NUM_ROWS * NUM_COLS;
constexpr byte stripPin = 7;
CRGB strip[NUM_LEDS];


void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, stripPin, GRB>(strip, NUM_LEDS);
  // UKRAINE
  fill_solid(&(strip[0]), NUM_LEDS / 2, CRGB::Blue);
  fill_solid(&(strip[NUM_LEDS / 2]), NUM_LEDS / 2, CRGB::Yellow);
  FastLED.show();
}

void loop() {}

this will get you

Now - explain the math on how you make it "wave" ?

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:

  1. Use "empty" (non-colored) rows above and below the flag, first raise column y+1, then y+0, then y-1.
  2. 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).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.