😎 different speeds for each line, use double buffer to avoid flickering

master
Felix Pankratz 4 days ago
parent 88971bd6ab
commit c52f004690

@ -36,21 +36,10 @@
MatrixPanel_I2S_DMA *matrix = nullptr;
uint16_t colorWheel(uint8_t pos) {
if(pos < 85) {
return matrix->color565(pos * 3, 255 - pos * 3, 0);
} else if(pos < 170) {
pos -= 85;
return matrix->color565(255 - pos * 3, 0, pos * 3);
} else {
pos -= 170;
return matrix->color565(0, pos * 3, 255 - pos * 3);
}
}
int line_pos[PANEL_WIDTH]; // where a rain marker is (y coordinate)
int line_length[PANEL_WIDTH]; // how long a line is for a given x coord
int line_speed[PANEL_WIDTH]; // how fast each line moves
unsigned long line_last_moved[PANEL_WIDTH];
void setup(){
Serial.begin(BAUD_RATE);
@ -58,8 +47,9 @@ void setup(){
for (int i = 0; i<PANEL_WIDTH; i++) {
line_pos[i] = 0 - random(24);
line_length[i] = random(12, 24);
line_speed[i] = random(10, 100);
line_length[i] = random(20, 28);
line_speed[i] = random(25, 100);
line_last_moved[i] = millis();
}
// redefine pins if required
HUB75_I2S_CFG::i2s_pins _pins={R1, G1, BL1, R2, G2, BL2, CH_A, CH_B, CH_C, CH_D, CH_E, LAT, OE, CLK};
@ -72,6 +62,8 @@ void setup(){
mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M;
mxconfig.clkphase = false;
mxconfig.double_buff = true;
matrix = new MatrixPanel_I2S_DMA(mxconfig);
matrix->begin();
matrix->setBrightness8(64);
@ -79,15 +71,19 @@ void setup(){
matrix->setFont(&CaveatBrush_Regular9pt7b);
}
uint8_t color = 0;
const char *str = "Panki";
void loop() {
matrix->fillScreenRGB888(0, 0, 0);
matrix ->flipDMABuffer();
matrix->clearScreen();
delay(25);
//matrix ->drawBitmap(0, 0, overlay, 64, 32, matrix->color565(64, 0, 0));
unsigned long timestamp = millis();
for (int x = 0; x < PANEL_WIDTH; x++) {
// step down a pixel
line_pos[x]++;
if ((timestamp - line_last_moved[x]) > line_speed[x]) {
// step down a pixel
line_pos[x]++;
line_last_moved[x] = timestamp;
}
if (line_pos[x] > PANEL_HEIGHT) {
line_pos[x] = 0;
}
@ -101,7 +97,6 @@ void loop() {
//}
int trail_y = line_pos[x] - trail_offset;
if (trail_y >= 0) {
//if (overlay[ (trail_y * PANEL_WIDTH) + x ]) {
int pixel_num = (trail_y * PANEL_WIDTH) + x;
if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) )) {
matrix->drawPixel(x, trail_y, matrix->color565(128, 255, 128));
@ -123,20 +118,6 @@ void loop() {
}
}
}
delay(100);
//for (color=0; color<256; color++) {
// // create a border
// matrix->drawRect(0, 0, matrix->width(), matrix->height(), colorWheel(color));
// matrix->drawRect(1, 1, matrix->width()-2, matrix->height()-2, colorWheel(color));
// matrix->setTextSize(1);
// matrix->setTextWrap(false);
// matrix->setCursor(8, 22);
// //const char *str = "Panki";
// matrix->setTextColor(colorWheel(color+128));
// matrix->print(str);
// delay(100);
//}
//delay(25);
}

Loading…
Cancel
Save