Hi,
I'm trying to make a countdown timer using a 32 x 64 LED Matrix and an Arduino Mega. I'm not sure why every time I send a string to the display, it duplicates it on the next row. I'd appreciate some help.
I followed this wiring diagram.
Here is my code
// testshapes demo for RGBmatrixPanel library.
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 32x64 RGB LED matrix.
// https://www.instructables.com/64x32-RGB-LED-Matrix-With-Arduino-Mega/
// https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/library
// https://tutorial45.com/building-an-arduino-countdown-timer/
// WILL NOT FIT on ARDUINO UNO -- requires a Mega, M0 or M4 board
#include <RGBmatrixPanel.h>
// Most of the signal pins are configurable, but the CLK pin has some
// special constraints. On 8-bit AVR boards it must be on PORTB...
// Pin 11 works on the Arduino Mega. On 32-bit SAMD boards it must be
// on the same PORT as the RGB data pins (D2-D7)...
// Pin 8 works on the Adafruit Metro M0 or Arduino Zero,
// Pin A4 works on the Adafruit Metro M4 (if using the Adafruit RGB
// Matrix Shield, cut trace between CLK pads and run a wire to A4).
//#define CLK 8 // USE THIS ON ADAFRUIT METRO M0, etc.
//#define CLK A4 // USE THIS ON METRO M4 (not M0)
#define CLK 11 // USE THIS ON ARDUINO MEGA
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
int S = 59; // count seconds
int M = 59; // count minutes
int H = 47; // count hours
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false,64); //add D after C,....and 64 after false,
void setup() {
matrix.begin(); //this line is needed for anything to show up\
matrix.setCursor(9,0);
matrix.setTextColor(matrix.Color333(7,7,0));
matrix.print("GO");
matrix.setTextColor(matrix.Color333(7,7,7));
matrix.print("CREATE");
}
void loop() {
//------------------------------CHANGE TIME---------------------------------
S--;
delay(1000);
matrix.fillScreen(0); //to refresh
matrix.setTextColor(matrix.Color333(0,0,0));
//DISPLAY MAKE 48 LOGO
matrix.setCursor(11,0);
matrix.setTextColor(matrix.Color333(4,7,0));
matrix.print("MAKE");
matrix.setTextColor(matrix.Color333(7,4,0));
matrix.print(" 48");
if (S<0) //if seconds are up,
{
M--; // reduce minute by one
S=59; // reset second section to 59
}
if (M<0) //if minutes are up,
{
H--; //reduce hour by one
M=59; //reset minute to 59
}
if (H<0){ //if hours are up, reset everything
H=23;
M=59;
S=59;
}
//----------------------------DISPLAY TIME-----------------------------
matrix.setCursor(8,16);
if (H>=32){ // Set color for time
matrix.setTextColor(matrix.Color333(4,7,0));
} else if (H <32 && H>=16){
matrix.setTextColor(matrix.Color333(7,7,0));
} else{
matrix.setTextColor(matrix.Color333(7,0,0));
}
if (H < 10){
matrix.print(" "); //Extra space is to ensure colons are in the same spot when theres only 1 digit
matrix.print(H);
} else {
matrix.print(H);
}
matrix.print(":");
if (M < 10){
matrix.print(" "); //Extra space is to ensure colons are in the same spot when theres only 1 digit
matrix.print(M);
} else {
matrix.print(M);
}
matrix.print(":");
if (S < 10){
matrix.print(" "); //Extra space is to ensure colons are in the same spot when theres only 1 digit
matrix.print(S);
} else {
matrix.print(S);
}
}
Blockquote