Hi - I am running an 8x32 matrix on a Teensy 3.2 using fastled in parallel. I'm displaying a sinusoid function. It works fine for about a minute and then slows to a framerate of about 2FPS - and keeps getting slower after that. Any ideas of what could be causing it?
Code:
#include "FastLED.h"
uint8_t Width = 32;
uint8_t Height = 8;
// y dimension x=0, y=0 at lower left hand corner (pixel 8)
float speed = 1.0; // speed of the movement along the Lissajous curves
float size = 4; // amplitude of the curves
// NUM_LEDS = Width * Height
#define NUM_LEDS_PER_STRIP 64
// Note: this can be 12 if you're using a teensy 3 and don't mind soldering the pads on the back
#define NUM_STRIPS 4
#define NUM_LEDS 256
#define BRIGHTNESS 100
#define FPS 100
#define FPS_DELAY 1000/FPS
CRGB leds[NUM_LEDS];
void setup() {
LEDS.addLeds<WS2811_PORTD, NUM_STRIPS, GRB>(leds, NUM_LEDS_PER_STRIP);
FastLED.setBrightness(BRIGHTNESS);
}
void loop()
{
sinusoid();
FastLED.show();
// FastLED.delay(FPS_DELAY);
}
void sinusoid()
{
for (uint8_t y = 0; y < Height; y++) {
for (uint8_t x = 0; x < Width; x++) {
float cx = y + float(size * (sinf (float(speed * 0.003 * (millis() ))) ) ) - (Width/2); // the 8 centers the middle on a 16x16
float cy = x + float(size * (cosf (float(speed * 0.0022 * (millis()))) ) ) - (Height/2);
float v = 127 * (1 + sinf ( sqrtf ( ((cx * cx) + (cy * cy)) ) ));
uint8_t data = v;
leds[XY(x, y)].r = data;
cx = x + float(size * (sinf (speed * float(0.0021 * (millis()))) ) ) - (Width/2);
cy = y + float(size * (cosf (speed * float(0.002 * (millis() ))) ) ) - (Height/2);
v = 127 * (1 + sinf ( sqrtf ( ((cx * cx) + (cy * cy)) ) ));
data = v;
leds[XY(x, y)].b = data;
cx = x + float(size * (sinf (speed * float(0.0041 * (millis() ))) ) ) - (Width/2);
cy = y + float(size * (cosf (speed * float(0.0052 * (millis() ))) ) ) - (Height/2);
v = 127 * (1 + sinf ( sqrtf ( ((cx * cx) + (cy * cy)) ) ));
data = v;
leds[XY(x, y)].g = data;
}
}
}
// Helper function that translates from x, y into an index into the LED array
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t ledNum;
if ( x & 0x01)
{
// Odd rows run backwards
ledNum = ((x+1) * Height) - (y+1);
}
else
{
// Even rows run forwards
ledNum = ((x * Height) + y);
}
return ledNum;
}
Last edited by a moderator: