Any advice? Thanks in advance.
Problem: When clock hours reach double digits the clock crashes.
Works fine from 1:00 to 9:59.
I think problem is around line 218, where 24hr is converted to 12hr.
Thank you very much for taking a look.
// Maxmatrix library:
// https://brainy-bits.com/tutorials/scroll-text-using-the-max7219-led-dot-matrix/
// https://code.google.com/p/arudino-maxmatrix-library/
// niq_ro from
// http://arduinotehniq.blogspot.com
// http://nicuflorica.blogspot.ro/
// original sketch - ver.4.0, Craiova, Romania, 5.8.2015
#include <MaxMatrix.h>
#include <avr/pgmspace.h>
#include <DS3231.h> //JC
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
int data = 12; // DIN pin of MAX7219 module
int load = 10; // CS pin of MAX7219 module
int clock = 11; // CLK pin of MAX7219 module
int maxInUse = 4; //how many MAX7219 are connected
MaxMatrix m(data, load, clock, maxInUse); // define Library
byte buffer[11]; //***JC
// char string1[] = " niq_ro test sketch from https://brainy-bits.com/tutorials/scroll-text-using-the-max7219-led-dot-matrix/ "; // Scrolling Text
//char string4[] = " temperature: "; // Fixxed text
//char string5[] = " relative humidity: "; // Fixxed text
char string6[] = " clock: "; // Fixxed text
// char string7[] = " date: "; // Fixxed text
#include <Wire.h>
#include "RTClib.h" // from https://github.com/adafruit/RTClib
RTC_DS1307 RTC; // Tells the RTC library that we're using a DS1307 RTC
byte spid = 35;
void setup(){
m.init(); // module MAX7219
m.setIntensity(1); // LED Intensity 0-15
byte c;
m.shiftLeft(false, true);
Wire.begin();
RTC.begin(); //works with either lib
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
int ftmp;
void loop(){
float te = 19.9; //--1307 - old read float -- sensor not present
if (!ftmp) te = te * 1.8 + 32;
//te = rtc.getTemp(); //--3231 -jc -this should be the value here.
int t2 = 10*te;
// http://www.arduino-hacks.com/converting-integer-to-character-vice-versa/
char c[3], d[2];
String str1, str2;
int t2z = t2/10;
int t2u = t2 - t2z*10;
str1=String(t2z);
str1.toCharArray(c,3);
str2=String(t2u);
str2.toCharArray(d,2);
printString1(" ", 1); //put OFF colon for temp
// TEMPERATURE DIGITS IN C AND D
printString1(c, 10);
printString1(d, 18);
if (ftmp){
ftmp = 0;
printString1("c", 26);
}else{
ftmp = 25;
printString1("*", 26);
}
delay(5000);
DateTime now = RTC.now();
int ora = now.hour();
int minut = now.minute();
// ***e and f are the hour and minute
// http://www.arduino-hacks.com/converting-integer-to-character-vice-versa/
char e[3], f[3];
String str3, str4;
str3=String(ora);
str3.toCharArray(e,3);
str4=String(minut);
str4.toCharArray(f,3);
// *** Print hour *********
if (ora > 12) ora = ora - 12; //convert from 24hr time
if (ora >= 10){
printString1("1", 2);
printString1(e-10, 10);
//printString1(e, 2); // same as line above
}
else
{
printString1(" ", 2);
printString1(e, 10);
}
printString1(":", 2); //put colon for time
// *** print minute **********
if (minut >= 10) printString1(f, 18);
else
{
printString1("0", 18);
printString1(f, 26);
}
delay(5000);
}
// Put extracted character on Display
void printCharWithShift(char c, int shift_speed){
if (c < 32) return;
c -= 32;
memcpy_P(buffer, CH + 8*c, 8);//***JC
m.writeSprite(maxInUse*8, 0, buffer);
m.setColumn(maxInUse*8 + buffer[0], 0);
for (int i=0; i<buffer[0]+1; i++)
// for (int i=0; i<buffer[0]+1; i++)
{
delay(shift_speed);
m.shiftLeft(false, false);
}
}
// Extract characters from Scrolling text
void printStringWithShift(char* s, int shift_speed){
while (*s != 0){
printCharWithShift(*s, shift_speed);
s++;
}
}
void printString(char* s)
{
int col = 0;
while (*s != 0)
{
if (*s < 32) continue;
char c = *s - 32;
memcpy_P(buffer, CH + 8*c, 8); //***JC
m.writeSprite(col, 0, buffer);
m.setColumn(col + buffer[0], 0);
col += buffer[0] + 1;
s++;
}
}
void printString1(char* s, int col)
{
int col1 = col;
while (*s != 0)
{
if (*s < 32) continue;
char c = *s - 32;
memcpy_P(buffer, CH + 8*c, 8); //***JC
m.writeSprite(col, 0, buffer);
m.setColumn(col + buffer[0], 0);
col += buffer[0] + 1;
s++;
}
}
AlmostCompleteNANO.ino (11.8 KB)