Hello All,
I too am working on a qty 2 by 4x7 segment display common cathode with DS1302RTC and TMP36 temp sensor input. I am using the MAX7219 for the multiplexing and have been successful in passing the temp reading to 4 of the 8 digits but all the RTC libraries I find rely on serial transfer for the RTC data to most often an LCD display, not a 7 segment and especially not via a MAX7129.
I have a reasonable code below that hopefully someone can make sense of. As I only have 4 digits left I only want to display the HH.MM data on the 7 seg. I have modified examples found about to serial.print the MIN and HOURS and am attempting to catch the data from the serial feed by using 'serial.available' and 'Time=serial.parseInt();' and then loading Time into a function which is almost the same as the function used to send the temp to the display (which works).
I can see the min and hour data on the serial monitor 002319000023190000231900002319...But i cant manage to grab it and use it for my function. Its driving me nuts. I just get "00.00" on the display.
I'm using the "LedControl.h" and <DS1302.h> libraries.
If someone could please take a look at my code especially void loop and please offer ideas on how to get the data off the serial and use it for my function I would appreciate it!
Thanks Jason.
#include "LedControl.h" // need the library
#include <DS1302.h>
LedControl lc=LedControl(12,11,10,1); // lc is our object
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219
DS1302 rtc(2, 3, 4);// Init the DS1302
// I assume you know how to connect the DS1302.
// DS1302: CE pin -> Arduino Digital 2
// I/O pin -> Arduino Digital 3
// SCLK pin -> Arduino Digital 4
int tempPin=A5;
float sample;
float tempC;
float tempF;
int TIME;
// Init a Time-data structure
Time t;
void setup()
{
pinMode(tempPin,INPUT);
lc.shutdown(0,false);// turn off power saving, enables display
lc.setIntensity(0,10);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
// Setup Serial connection
Serial.begin(9600);
// The following lines can be commented out to use the values already stored in the DS1302
rtc.setTime(23,19,44); // Set the time to 12:00:00 (24hr format)
}
void printNumber(float num)
{
int ones;
int tens;
int hundreds;
int v=(int)num;
float diff=num-v;
diff=diff*100;
int fones,ftens;
fones=(int)diff%10;
diff=diff/10;
ftens=(int)diff%10;
diff=diff/10;
ones=v%10;
v=v/10;
tens=v%10;
v=v/10;
hundreds=v;
//Now print the number digit by digit
// lc.setDigit(0,4,(byte)hundreds,false);
lc.setDigit(0,3,(byte)tens,false);
lc.setDigit(0,2,(byte)ones,true);
lc.setDigit(0,1,(byte)ftens,false);
//lc.setDigit(0,0,(byte)fones,false);
lc.setChar(0,0,'c',false);
}
void printTime(float num)
{
int ones;
int tens;
int hundreds;
int thou;
int tenthou;
int v=(int)num;
float diff=num-v;
diff=diff*100;
int fones,ftens;
fones=(int)diff%10;
diff=diff/10;
ftens=(int)diff%10;
diff=diff/10;
ones=v%10; ///12345 ==> 1234.5 so 5 is remainder
v=v/10; ///12545/10 ==> 1234 int
tens=v%10; ///1234 ==> 123.4 so 4 is remainder
v=v/10; ///1234/10 ==> 123 int
hundreds=v%10; ///123 ==> 12.3 so 3 is remainder
v=v/10; ///123/10 ==> 12 int
thou=v%10; ///12 ==> 1.2 so 2 is remainter
v=v/10; ///12/10 ==> 1 int
tenthou=v%10; ///1 ==> 0.1 so 1 is remainder
//Now print the number digit by digit
lc.setDigit(0,7,(byte)thou,false);
lc.setDigit(0,6,(byte)hundreds,false);
lc.setDigit(0,5,(byte)tens,false);
lc.setDigit(0,4,(byte)ones,false);
}
void loop()
{
sample=0;
for(int i=0;i<150;i++)
{
sample+=analogRead(tempPin); //read the value from the sensor
delay(2);
}
{
sample=sample/150;
tempC=(sample*100.0)/1023.0; //convert the analog data to temperature
printNumber(tempC);
}
///////////////////////////////////
while(1)
{
// Get data from the DS1302
t = rtc.getTime();
Serial.print(t.hour, DEC);
Serial.print(t.min, DEC);
while (Serial.available() > 0)
{
TIME = Serial.parseInt();
}
printTime((float)TIME);
delay(1000);
}
delay(1000);
}