I am trying to make a led matrix clock using a 32x8 led matrix module using max7219 ic & ds3231 as the RTC. I tried every library i could find for the matrix module to show text/numbers but none of them worked properly for me. As, the module is a cheap chinese one and its wiring is different then the ones all those libraries are made for.
Then i made the characters as a byte array, and made a sketch to call those arrays if the right condition was met. like this,
if(rh = 1) {
for (int i = 0; i < 8; i++) {
lc.setRow(2,i,number1[i]);}}
if(rh = 2) {
for (int i = 0; i < 8; i++) {
lc.setRow(2,i,number2[i]);}}
but , even if rh = 1 it would run both statements. Giving me a flickering two or more digits on the matrix.
What can i do so that when rh = 1 it only executes the if statement for that and not touch the others.
The sketch i have written so far is given below.
#include "LedControl.h"
#include <DS3231_Simple.h>
DS3231_Simple Clock;
/*
* Pin 12 is connected to the DATA IN-pin of the first MAX7221
* Pin 11 is connected to the CLK-pin of the first MAX7221
* Pin 10 is connected to the LOAD(/CS)-pin of the first MAX7221
* SCL of RTC is connected to A5
* SDA of RTC is connected to A4
*/
LedControl lc=LedControl(12,11,10,4);
unsigned long delaytime=200;
//Digits for the displays
byte number0[] ={B00011100,B00100010,B00100010,B00100010,B00100010,B00100010,B00011100,B00000000};
byte number1[] ={B00001000,B00011000,B00001000,B00001000,B00001000,B00001000,B00011100,B00000000};
byte number2[] ={B00011100,B00100010,B00000010,B00011100,B00100000,B00100000,B00111110,B00000000};
byte number3[] ={B00111110,B00000010,B00000100,B00001100,B00000010,B00100010,B00011100,B00000000};
byte number4[] ={B00000100,B00001100,B00010100,B00100100,B00111110,B00000100,B00000100,B00000000};
byte number5[] ={B00111110,B00100000,B00111100,B00000010,B00000010,B00100010,B00011100,B00000000};
byte number6[] ={B00001110,B00010000,B00100000,B00111100,B00100010,B00100010,B00011100,B00000000};
byte number7[] ={B00111110,B00000010,B00000010,B00000100,B00001000,B00010000,B00100000,B00000000};
byte number8[] ={B00011100,B00100010,B00100010,B00011100,B00100010,B00100010,B00011100,B00000000};
byte number9[] ={B00011100,B00100010,B00100010,B00011110,B00000010,B00000100,B00111000,B00000000};
void setup() {
Serial.begin(9600);
Clock.begin();
//Wake up displays
lc.shutdown(0,false);
lc.shutdown(1,false);
lc.shutdown(2,false);
lc.shutdown(3,false);
//Set intensity
lc.setIntensity(0,1);
lc.setIntensity(1,1);
lc.setIntensity(2,1);
lc.setIntensity(3,1);
//Clear displays
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
}
void loop() {
//Time
DateTime MyDateAndTime; // Variable to hold RTC data
MyDateAndTime = Clock.read(); // Read RTC data
// Variable for 4 digits
int lh = ((MyDateAndTime.Hour/10)%10); // Hour left digit
int rh = (MyDateAndTime.Hour%10); // Hour right digit
int lm = ((MyDateAndTime.Minute/10)%10); // Minute left digit
int rm = (MyDateAndTime.Minute%10); // Minute right digit
//Time debugging
Serial.print("Hour: left "); Serial.println(lh);
Serial.print("Hour: right "); Serial.println(rh);
Serial.print("Minute: left "); Serial.println(lm);
Serial.print("Minute: right "); Serial.println(rm);
Serial.println("");
// Display
// First digit or display address 3
if(lh = 1){for (int i = 0; i < 8; i++) {
lc.setRow(3,i,number1[i]);}}
if(lh = 2){for (int i = 0; i < 8; i++) {
lc.setRow(3,i,number2[i]);}}
else
{
for (int i = 0; i < 8; i++) {
lc.setRow(3,i,number0[i]);}}
// Second digit or display address 2
if(rh = 1) {
for (int i = 0; i < 8; i++) {
lc.setRow(2,i,number1[i]);}}
if(rh = 2) {
for (int i = 0; i < 8; i++) {
lc.setRow(2,i,number2[i]);}}
}