Go Down

Topic: Matrix clock RTC (Read 1 time) previous topic - next topic

SaSaa

Oct 25, 2010, 12:23 am Last Edit: Oct 25, 2010, 12:38 am by sasaa Reason: 1
Hi there,
I'm trying to make a nice clock for the master bedroom.
I got 4 rainbowdouino's with RGB matrixes on them.
it works great.

although I have no trouble trying to display the time of my "ladyada's log shield" over serial.

I want to display the time on the four matrixes so that every matrix just shows one number (only hours and minutes)

But i never worked with a RTC before so hoped to learn something here :P

If possible i love to have the seconds to but i dont know how.
32x8 pixels is a lot so it should work

SaSaa

#1
Oct 25, 2010, 09:16 pm Last Edit: Oct 25, 2010, 09:24 pm by sasaa Reason: 1
I'm able to output it on my LCD's and the serial monitotr but not on the 4 matrices and it really bugs me.

the real problem is that i don't understand how to write it to the display when the numbers are bigger then 9 because it will then take 2 matrices to show the value

the serial monitoris very simple because its as simple as taken from the official example

Code: [Select]
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
   Serial.begin(57600);
   Wire.begin();
   RTC.begin();

 if (! RTC.isrunning()) {
   Serial.println("RTC is NOT running!");
   // following line sets the RTC to the date & time this sketch was compiled
   RTC.adjust(DateTime(__DATE__, __TIME__));
 }
}

void loop () {
   DateTime now = RTC.now();
   
   Serial.print(now.year(), DEC);
   Serial.print('/');
   Serial.print(now.month(), DEC);
   Serial.print('/');
   Serial.print(now.day(), DEC);
   Serial.print(' ');
   Serial.print(now.hour(), DEC);
   Serial.print(':');
   Serial.print(now.minute(), DEC);
   Serial.print(':');
   Serial.print(now.second(), DEC);
   Serial.println();
   
   Serial.print(" since midnight 1/1/1970 = ");
   Serial.print(now.unixtime());
   Serial.print("s = ");
   Serial.print(now.unixtime() / 86400L);
   Serial.println("d");
   
   // calculate a date which is 7 days and 30 seconds into the future
   DateTime future (now.unixtime() + 7 * 86400L + 30);
   
   Serial.print(" now + 7d + 30s: ");
   Serial.print(future.year(), DEC);
   Serial.print('/');
   Serial.print(future.month(), DEC);
   Serial.print('/');
   Serial.print(future.day(), DEC);
   Serial.print(' ');
   Serial.print(future.hour(), DEC);
   Serial.print(':');
   Serial.print(future.minute(), DEC);
   Serial.print(':');
   Serial.print(future.second(), DEC);
   Serial.println();
   
   Serial.println();
   delay(3000);
}


how do i get this "Serial.print(now.day(), DEC);" and split the digits if there are 2 :S so i can put in this

Code: [Select]
#include <Wire.h>

unsigned char RainbowCMD[5];
unsigned char State = 0;  
unsigned long timeout;


void setup()
{
 Wire.begin(); // join i2c bus (address optional for master)
}

void loop()
{
 ShowChar(4,DIGIT1,0,0,15,0);ShowChar(3,DIGIT2,0,0,15,0);ShowChar(2,DIGIT3,0,0,15,0);ShowChar(1,DIGIT4,0,0,15,0); // time NOT working
 delay(1000);
}





//--------------------------------------------------------------------------
//Name:ShowColor
//function: Send a conmand to Rainbowduino for showing a color
//parameter: Address: rainbowduino IIC address
//                 red,green,blue:  the color RGB    
//----------------------------------------------------------------------------
void ShowColor(int Address,unsigned char red , unsigned char green, unsigned char blue)
{
 RainbowCMD[0]='R';
 RainbowCMD[1]=0x03;
 RainbowCMD[2]=red;
 RainbowCMD[3]=((green<<4)|(blue));

  SentCMD(Address);
}


//--------------------------------------------------------------------------
//Name:ShowImage
//function: Send a conmand to Rainbowduino for showing a picture which was pre-set in Rainbowduino Flash
//parameter: Address: rainbowduino IIC address
//                 number:  the pre-set picture position
//                 shift: the picture  shift bit for display
//----------------------------------------------------------------------------
void ShowImage(int Address, unsigned char number,unsigned char shift)
{
   RainbowCMD[0]='R';
   RainbowCMD[1]=0x01;
   RainbowCMD[2]=(shift<<4);
   RainbowCMD[4]=number;

    SentCMD(Address);
}



//--------------------------------------------------------------------------
//Name:ShowColor
//function: Send a conmand to Rainbowduino for showing a color
//parameter: Address: rainbowduino IIC address
//                 red,green,blue:  the color RGB  
//                 shift: the picture  shift bit for display
//                 ASCII:the char or Number want to show
//----------------------------------------------------------------------------
void ShowChar(int  Address,unsigned char ASCII,unsigned char red, unsigned char blue ,unsigned char green,unsigned char shift)
{
   RainbowCMD[0]='R';
   RainbowCMD[1]=0x02;
   RainbowCMD[2]=((shift<<4)|(red));
   RainbowCMD[3]=((green<<4)|(blue));
   RainbowCMD[4]=ASCII;
     
    SentCMD(Address);
}




//--------------------------------------------------------------------------
//Name:SentCMD
//function: Send a 5 byet Rainbow conmand out
//parameter: NC  
//----------------------------------------------------------------------------
void SentCMD(int  Add)
{   unsigned char OK=0;
    unsigned char i,temp;

   while(!OK)
 {                          
   switch (State)
   {       

   case 0:                          
     Wire.beginTransmission(Add);
     for (i=0;i<5;i++) Wire.send(RainbowCMD[i]);
     Wire.endTransmission();    
     delay(5);  
     State=1;                      
     break;

   case 1:

     Wire.requestFrom(Add,1);  
     if (Wire.available()>0)
       temp=Wire.receive();    
     else {
       temp =0xFF;
       timeout++;
     }

     if ((temp==1)||(temp==2)) State=2;
     else if (temp==0) State=0;

     if (timeout>5000)
     {
       timeout=0;
       State=0;
     }

     delay(5);
     break;

   case 2:
     OK=1;
     State=0;
     break;

   default:
     State=0;
     break;

   }
 }
}
i really don't know :S

Korman

#2
Oct 25, 2010, 09:43 pm Last Edit: Oct 25, 2010, 09:44 pm by Korman Reason: 1
I don't know where the magic DIGIT1 to DIGIT4 are coming from, but lets assume they're the puzzle to solve. Add this code to the top of your loop() function (as usual untested, the problem isn't interesting enough to start the IDE):

Code: [Select]
DateTime now = RTC.now();
char DIGIT1 = '0' + now.hour() / 10;
char DIGIT2 = '0' + now.hour() % 10;
char DIGIT3 = '0' + now.minute() / 10;
char DIGIT4 = '0' + now.minute() % 10;


Korman

SaSaa

#3
Oct 26, 2010, 07:35 am Last Edit: Oct 26, 2010, 07:37 am by sasaa Reason: 1
I will try it when I get home in about 9 hours :-P
the digit1 to 4 are just part of my explaination*


SaSaa

It works GREAT ! I really love Open Source :P

thanks Korman.
I'll post my complete code soon :D

Go Up