diff --git a/nametag/src/main.cpp b/nametag/src/main.cpp index 2cb5e3b..ed3c95c 100644 --- a/nametag/src/main.cpp +++ b/nametag/src/main.cpp @@ -41,15 +41,30 @@ 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]; +typedef struct { + int y; + int length; + int speed; + unsigned long last_moved; +} Raindrop; + +Raindrop raindrops[PANEL_WIDTH]; + void setup(){ Serial.begin(BAUD_RATE); pinMode(ONBOARD_LED, OUTPUT); for (int i = 0; iflipDMABuffer(); 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++) { - if ((timestamp - line_last_moved[x]) > line_speed[x]) { + if ((timestamp - raindrops[x].last_moved) > raindrops[x].speed) { // step down a pixel - line_pos[x]++; - line_last_moved[x] = timestamp; + raindrops[x].y++; + raindrops[x].last_moved = timestamp; } - if (line_pos[x] > PANEL_HEIGHT) { - line_pos[x] = 0; + if (raindrops[x].y > PANEL_HEIGHT) { + raindrops[x].y = 0; } - if (line_pos[x] >= 0) { + if (raindrops[x].y >= 0) { //draw our pixel - matrix->drawPixel(x, line_pos[x], matrix->color565(128, 255, 128)); + matrix->drawPixel(x, raindrops[x].y, matrix->color565(128, 255, 128)); // draw our trail - for (int trail_offset = 1; trail_offset < line_length[x]; trail_offset++) { - //if (random(10) > 8) { - // trail_offset++; - //} - int trail_y = line_pos[x] - trail_offset; + for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) { + int trail_y = raindrops[x].y - trail_offset; if (trail_y >= 0) { 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)); } else { - matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / line_length[x]) * (line_length[x] - trail_offset), 0)); + matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0)); } } else { int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x; @@ -109,7 +120,7 @@ void loop() { if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) )) { matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(128, 255, 128)); } else { - matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / line_length[x]) * (line_length[x] - trail_offset), 0)); + matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0)); } } else { break; @@ -118,6 +129,5 @@ void loop() { } } } - //delay(25); }