Go Down

Topic: Arduino set clock arrays help (Read 5510 times) previous topic - next topic

PaulS

Quote
the output will be 1234 but i don`t know how to swap to set month you see

That should be something like:
Code: [Select]
   if(a < 4)
   {
      year[a] = key;
       a++;
      if (a == 4)
      {
         Serial.println(year);
      }
   }
   else if(m < 2)
   {
       // do the month stuff
   }
   else if(d < 2)
   {
       // do the day stuff
   }
   else
   {
       // set the clock
   }
The art of getting good answers lies in asking good questions.

mariusnet

and the beer goes toooo Seattle
Code: [Select]

if(a < 4)
   {
      year[a] = key;
       a++;
      if (a == 4)
      {
         Serial.println(year);
      }
   }
   else if(m < 2)
   {
             month[m] = key;
       m++;
      if (m == 2){
         Serial.println(month);
      }
   }
   else if(d < 2)
   {
             day[d] = key;
       d++;
      if (d == 2){
         Serial.println(day);
      }
   }
      else if(h < 2)
   {
             hour[h] = key;
       h++;
      if (h == 2){
         Serial.println(hour);
      }
   }
      else if(mi < 2)
   {
             min[mi] = key;
       mi++;
      if (mi == 2){
         Serial.println(min);
      }
   }

we have a beer goes to UK as well
thank you for help

mariusnet

#17
Nov 05, 2013, 12:00 pm Last Edit: Nov 05, 2013, 12:02 pm by mariusnet Reason: 1
ok there is another problem ... and i cannot found it on internet
i have my char year  what on serial show up 2013 and when i try to set the clock i get this error
lcd_key_clock:188: error: initializing argument 2 of 'void DS1307::set(int, int)'
lcd_key_clock:189: error: invalid conversion from 'char*' to 'int'
the line is :
   RTC.set(DS1307_YR,(year));         //set the year
any bit of help please?
thank you

PaulS

Quote
any bit of help please?

You should use http://snippets-r-us.com to get answers about your snippet.
The art of getting good answers lies in asking good questions.

mariusnet

#19
Nov 05, 2013, 12:21 pm Last Edit: Nov 05, 2013, 12:29 pm by mariusnet Reason: 1
Code: [Select]

#include <bv4618_I.h>
#include <Wire.h>

#include <DS1307.h>

BV4618_I di(0x31,9); // 0x62 I2C address (8 bit)
const char kb[]={
  0xD7,0xee,0xde,0xbe,0xed,0xdd,0xbd,0xeb,0xdb,0xbb,0x7e,0x7D,0x7b,0x77,0xe7,0xb7};
//char key;
char year[4];
char month[2];
char day[2];
char hour[2];
char min[2];
int a = 0;
int m = 0;
int d = 0;
int h = 0;
int mi = 0;

void setup () {
  Serial.begin(9600);
  di.setdisplay(4,20);
  di.setkeycodes(kb);
  Wire.begin();



}

void loop () {
  while (1){ // do forever
    if(di.keys()){
      char key=di.key();
      if(key > 9) key+='A'-10;
      else key+='0';
      if (key == 'A'){
        di.cls();
        di.rowcol(1,3);
        di.puts("SET Date/Time");
        di.rowcol(2,5);
             setYear();
      }
    }
void setYear(){
  di.rowcol(3,8);
  while (1){
    if(di.keys()){
      char key=di.key();
      if(key > 9) key+='A'-10;
      else key+='0';
      di.putch(key);
if(a < 4)
   {
      year[a] = key;
       a++;
      if (a == 4)
      {
         Serial.println(year);
      }
   }
   else if(m < 2)
   {
             month[m] = key;
       m++;
      if (m == 2){
         Serial.println(month);
      }
   }
   else if(d < 2)
   {
             day[d] = key;
       d++;
      if (d == 2){
         Serial.println(day);
      }
   }
      else if(h < 2)
   {
             hour[h] = key;
       h++;
      if (h == 2){
         Serial.println(hour);
      }
   }
      else if(mi < 2)
   {
             min[mi] = key;
       mi++;
      if (mi == 2){
         Serial.println(min);
      }
   }
           RTC.stop();
  RTC.set(DS1307_SEC,0);        //set the seconds
  RTC.set(DS1307_MIN, min);     //set the minutes
  RTC.set(DS1307_HR, hour);       //set the hours
   RTC.set(DS1307_DATE, day);       //set the date
  RTC.set(DS1307_MTH,month);        //set the month
  RTC.set(DS1307_YR,year);         //set the year
  RTC.start();
          return;
        }
      }
    }
  }
}

this is the full code. for setting up the clock
the error is :
initializing argument 2 of 'void DS1307::set(int, int)'
invalid conversion from 'char*' to 'int'
thank you

AWOL

Code: [Select]
lcd_key_clock:188: error: initializing argument 2 of 'void DS1307::set(int, int)'
lcd_key_clock:189: error: invalid conversion from 'char*' to 'int'

Your "set" method expects two integers - the first is a label (like "DS1307_YR"  to tell the library where to put the second integer, but you're not supplying an integer, you're supplying a char array.
Convert the value in "year" to an "int" and pass the "int" to the "set" method.

mariusnet

#21
Nov 05, 2013, 12:33 pm Last Edit: Nov 05, 2013, 12:41 pm by mariusnet Reason: 1
can you example the conversion please?

AWOL

Code: [Select]
char year[5];
int yy;
...
...
      if(a < 4)
      {
        year[a] = key;
        a++;
        if (a == 4)
        {
          year [4] ='\0';
          yy = atoi (year);
          Serial.println(yy);
        }

Same for day, month etc.

Please use the auto-format tool before posting code.

mariusnet


odometer

You don't need to use character arrays or [font=Courier]atoi()[/font].
Simple arithmetic (multiplication and addition) will suffice.

I would use something like:
int yy;
...
...
      if(a < 4)
      {
        if (a == 0) yy = key;
        else yy = (10 * yy) + key;
        a++;
        if (a == 4)
        {
          Serial.println(yy);
        }

Go Up