Go Down

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

robtillaart

#8
Nov 16, 2010, 11:32 am Last Edit: Nov 16, 2010, 11:34 am by robtillaart Reason: 1
Please modify your posting and use the # button for code blocks (so it becomnes readable).

I have used the library with no problems, so it might be the installation. Have you tried to download & install the latest version of the library again?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

cfc

I'm using RTClib files to test ds1307 RTC on data logger shield from Adafruit. Trying to compile ds1307.pde I get error that RTClib.h has many stray '\240'.
Here is the .h file itself
// Released to the public domain! Enjoy!

// Simple general-purpose date/time class (no TZ / DST / leap second handling!)
class DateTime {
public:
    DateTime (uint32_t t =0);
    DateTime (uint16_t year, uint8_t month, uint8_t day,
                uint8_t hour =0, uint8_t min =0, uint8_t sec =0);
    DateTime (const char* date, const char* time);
    uint16_t year() const       { return 2000 + yOff; }
    uint8_t month() const       { return m; }
    uint8_t day() const         { return d; }
    uint8_t hour() const        { return hh; }
    uint8_t minute() const      { return mm; }
    uint8_t second() const      { return ss; }
    uint8_t dayOfWeek() const;

    // 32-bit times as seconds since 1/1/2000
    long secondstime() const;  
    // 32-bit times as seconds since 1/1/1970
    uint32_t unixtime(void) const;

protected:
    uint8_t yOff, m, d, hh, mm, ss;
};

// RTC based on the DS1307 chip connected via I2C and the Wire library
class RTC_DS1307 {
public:
  static uint8_t begin(void);
    static void adjust(const DateTime& dt);
    uint8_t isrunning(void);
    static DateTime now();
};

// RTC using the internal millis() clock, has to be initialized before use
// NOTE: this clock won't be correct once the millis() timer rolls over (>49d?)
class RTC_Millis {
public:
    static void begin(const DateTime& dt) { adjust(dt); }
    static void adjust(const DateTime& dt);
    static DateTime now();

protected:
    static long offset;
};



AND the pde file is ds1307 as follows:
// 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);
}


Any ideas?

SaSaa


finally got the time to post my clock code
Code: [Select]
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

unsigned char RainbowCMD[5];
unsigned char State = 0;  
unsigned long timeout;
long previousMillis = 0;
long interval = 5 * 1000; // elke 20 seconden verrandert de kleur.
int r_time = 1;
int g_time = 1;
int b_time = 1;

void setup()
{
 Wire.begin();
 RTC.begin();
 // RTC.adjust(DateTime(__DATE__, __TIME__)); // Correct time
 delay(5000);
 ShowColor(4,15,0,0); ShowColor(3,0,15,0); ShowColor(2,0,0,15); ShowColor(1,15,15,15);
 delay(5000);
}

void loop(){
 DateTime now = RTC.now();
 char time1 = '0' + now.hour() / 10; if(time1 == '0'){ ShowChar(4,'0',0, 0, 0,0); }
 char time2 = '0' + now.hour() % 10; ShowChar(3,time2, r_time, g_time, b_time,0);
 char time3 = '0' + now.minute() / 10; ShowChar(2,time3, r_time, g_time, b_time,0);
 char time4 = '0' + now.minute() % 10;  ShowChar(1,time4, r_time, g_time, b_time,0);
 delay(500);
 SetPixelXY(2, 0, 2, r_time, g_time, b_time);
 SetPixelXY(2, 0, 5, r_time, g_time, b_time);
 delay(500);
 unsigned long currentMillis = millis();
 if(currentMillis - previousMillis > interval) {
   previousMillis = currentMillis;
   if(r_time != 0){
     r_time = 0;
     g_time = 1;
     b_time = 0;
   }else if(g_time != 0){
     r_time = 0;
     g_time = 0;
     b_time = 1;
   } if(b_time != 0){
     r_time = 1;
     g_time = 0;
     b_time = 0;
   }
 }
}

void ShowColor(int Adr, unsigned char R, unsigned char G, unsigned char B) {
 unsigned char shift;
 RainbowCMD[0]='R';
 RainbowCMD[1]=0x03;
 RainbowCMD[2] = B;
 RainbowCMD[3]=((G<<4)|(R));
 SentCMD(Adr);
}

void SetPixelXY(int Adr, unsigned char X, unsigned char Y, unsigned char R, unsigned char G, unsigned char B) {
 unsigned char TranslateX[8]={6,7,4,5,2,3,0,1};
 X = TranslateX[X];
 RainbowCMD[0] = 'R';
 RainbowCMD[1] = 0x04;
 RainbowCMD[2] = R;
 RainbowCMD[3] = ((G<<4)|(B));
 RainbowCMD[4] = ((X<<4)|(Y));
 SentCMD(Adr);
}

void ShowChar(int  Address,unsigned char ASCII,unsigned char red, unsigned char green ,unsigned char blue,unsigned char shift)
{
   RainbowCMD[0]='R';
   RainbowCMD[1]=0x02;
   RainbowCMD[2]=((shift<<4)|(red));
   RainbowCMD[3]=((green<<4)|(blue));
   RainbowCMD[4]=ASCII;
   SentCMD(Address);
}

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;

   }
 }
}

SaSaa

It works GREAT ! I really love Open Source :P

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

SaSaa

#4
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*


Go Up