RealTime Clock uint8_t question

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
keepersgain
 
Posts: 38
Joined: Mon Apr 15, 2013 7:18 am

RealTime Clock uint8_t question

Post by keepersgain »

Hi,

I'm creating a clock and i'm using the DS1307. I just want to grab the seconds from it. So... I create this "DateTime now;" and then in my code I write "int seconds = now.second;". The compiler doesn't like this.

How do I extract the seconds from DateTime as an integer? and what is an uint8_t?

Thanks

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: RealTime Clock uint8_t question

Post by adafruit_support_bill »

The compiler doesn't like this.
It would be helpful if you could post your code and the actual error messages.
what is an uint8_t?
It is an unsigned, 8-bit integer. It can hold values between 0 and 255.

User avatar
keepersgain
 
Posts: 38
Joined: Mon Apr 15, 2013 7:18 am

Re: RealTime Clock uint8_t question

Post by keepersgain »

Hi,

This is the code i'm using

Code: Select all

 int seconds;

  seconds = now.second  
  seconds = seconds % 10;
I've included this at the start

Code: Select all

#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
DateTime now;
and have a function that does this

Code: Select all

void GetDate(){

 now = RTC.now();

} 

and i get this error.

Binary_Clock_Light_Test:171: error: argument of type 'uint8_t (DateTime::)()const' does not match 'int'

What i would like to o is pull the hours mins and seconds out of the RTC. I assumed that they would be integers. I thought i might be able to coerce the uint8_t to an integer but that doesn't seam to work as well.


Keepersgain

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: RealTime Clock uint8_t question

Post by adafruit_support_bill »

You should have no problem converting from a uint8_t to an int.

Post the complete code so we can try to compile it. From the fragments you have posted there all I can see is that you are missing a semicolon at the end the first assignment statement:

Code: Select all

int seconds;

  seconds = now.second  
  seconds = seconds % 10;

User avatar
keepersgain
 
Posts: 38
Joined: Mon Apr 15, 2013 7:18 am

Re: RealTime Clock uint8_t question

Post by keepersgain »

Hi,

Here's all the code.

Code: Select all

#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
DateTime now;

int TheData[] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0};

int rows[] = {10,11,9,3};
int cols[] = {7,6,5,4,8,2};

//column data
int Col1[] = {0,1,0,1};
int Col2[] = {1,0,1,0};
int Col3[] = {0,1,0,1};
int Col4[] = {0,0,0,0};
int Col5[] = {0,1,0,1};
int Col6[] = {0,0,0,0};

int bigcount;
// bit mask
const int powers[] = {1,2,4,8,16,32,64,128};


// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(3, OUTPUT); 
  pinMode(9, OUTPUT); 
  pinMode(10, OUTPUT); 
  pinMode(11, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  Serial.begin(9600);
  // zero all columns
  Zero();
 // set up clock
 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__));
}
}
// the loop routine runs over and over again forever:
void loop() {
  
  
Flash();
  
  
  //delay(1000);
  SetSeconds();
  
  GetDate();
  
  
 
  //DrawData();
  //MoveData();
}
    
void Flash(){
      int z = 0;
      
      for (int c= 0; c<6; c++){
        for(int r = 0; r< 4; r++){
         z++;
        //Serial.println(z);
        //Serial.println(TheData[z]);
        if(TheData[z] == 1){
        digitalWrite(rows[r],HIGH);
        digitalWrite(cols[c],LOW);
        
        } 
        //delay(100);
    
        //if(TheData[z] = 0){
        digitalWrite(rows[r],LOW);
        digitalWrite(cols[c],HIGH);
        //}  
      }
      
      }
  }
 
 
 void DrawData(){
   
int   c= 3;
   for(int r = 0; r< 4; r++){
      if(Col1[r] == 0){
        digitalWrite(rows[r],HIGH);
        digitalWrite(cols[c],LOW);
      }
      if(Col1[r] == 1){
        digitalWrite(cols[c],HIGH);
        digitalWrite(rows[r],LOW);
      }
   }
   Zero();
   c= 1;
   for(int r = 0; r< 4; r++){
      if(Col2[r] == 0){
        //digitalWrite(rows[r],HIGH);
        //digitalWrite(cols[c],LOW);
      }
      if(Col2[r] == 1){
        //digitalWrite(cols[c],HIGH);
        //digitalWrite(rows[r],LOW);
      }
   } 
   Zero();
   /*
   for(int r = 0; r< 4; r++){
      for (int c= 0; c<6; c++){
        
        
        digitalWrite(rows[r],HIGH);
        digitalWrite(cols[c],LOW);
         
        delay(100);
    
        digitalWrite(cols[c],HIGH);
        digitalWrite(rows[r],LOW);
        }
      }*/
  }
   
 void Zero(){
 
 for (int c= 0; c<6; c++){
        digitalWrite(cols[c],HIGH);
         }
       
 }  
   
 void MoveData(){
   
   bigcount = bigcount +1;
   if(bigcount >1000){
     TheData[0] = TheData[1];
  for(int x = 1;x<24;x++){
     TheData[x] = TheData[x+1];
  }
   bigcount = 0;
   }
   
   
 }
  
void GetDate(){

 now = RTC.now();

}  
   
void SetSeconds(){
  
  //uint8_t n;

  
  int seconds;

  seconds = now.second;
  seconds = seconds % 10;
  
  Serial.println(seconds);
  Serial.println(now.second(), DEC);
  
  if(seconds == 0){
  TheData[1] = 0;
  TheData[2] = 0;
  TheData[3] = 0;
  TheData[4] = 0;
  }
    if(seconds == 1){
  TheData[1] = 1;
  TheData[2] = 0;
  TheData[3] = 0;
  TheData[4] = 0;
  }
    if(seconds == 2){
  TheData[1] = 0;
  TheData[2] = 1;
  TheData[3] = 0;
  TheData[4] = 0;
  }
    if(seconds == 3){
  TheData[1] = 1;
  TheData[2] = 1;
  TheData[3] = 0;
  TheData[4] = 0;
  }
    if(seconds == 4){
  TheData[1] = 0;
  TheData[2] = 0;
  TheData[3] = 1;
  TheData[4] = 0;
  }
    if(seconds == 5){
  TheData[1] = 1;
  TheData[2] = 0;
  TheData[3] = 1;
  TheData[4] = 0;
  }
    if(seconds == 6){
  TheData[1] = 0;
  TheData[2] = 1;
  TheData[3] = 1;
  TheData[4] = 0;
  }
    if(seconds == 7){
  TheData[1] = 1;
  TheData[2] = 1;
  TheData[3] = 1;
  TheData[4] = 0;
  }
    if(seconds == 8){
  TheData[1] = 0;
  TheData[2] = 0;
  TheData[3] = 0;
  TheData[4] = 1;
  }
    if(seconds == 9){
  TheData[1] = 1;
  TheData[2] = 0;
  TheData[3] = 0;
  TheData[4] = 1;
  }
  }
  
  
Thanks

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: RealTime Clock uint8_t question

Post by adafruit_support_bill »

second() is a function, not a property. You need a pair of parentheses after it.

Code: Select all

  int seconds;

  seconds = now.second();
  seconds = seconds % 10;

User avatar
keepersgain
 
Posts: 38
Joined: Mon Apr 15, 2013 7:18 am

Re: RealTime Clock uint8_t question

Post by keepersgain »

Doh!

I don't believe it! So, i need to look in the header to find out all this info, I can't view the header file in the ide, is that correct? I have to find it in the OS and open it from there.

Thanks for your prompt replies and help.

Keepersgain

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: RealTime Clock uint8_t question

Post by adafruit_support_bill »

I can't view the header file in the ide, is that correct?
Unfortunately, yes. The example sketches that come with the libraries are usually helpful though.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”