Arduino set clock arrays help

hello everyone
i`m trying to program my arduino to setup the clock but i-m getting stuck in to the arrays
can i have a small little help please?
the code is here:

#include <bv4618_I.h>
#include <Wire.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);
  di.cls();
  di.cls();
  di.puts("display test");
  di.rowcol(1,1);
}
void loop(){
  setYear();
}
void setYear(){
  while (1){ // do forever
    if(di.keys()){
      char key=di.key();
      if(key > 9) key+='A'-10;
      else key+='0';
      year[a] = key;
       a++;
      if (a == 4){
      Serial.println(year);
      if (m == 0){
       month[m] = key;
              m++;
        if (m == 2){
          Serial.println(month);
          //key = 0;
        day[d] = key;
        d++;
        //Serial.println(day);
      }
      }
    }
  }

}
}

thank you

but i-m getting stuck in to the arrays

What does this mean?

Why does setYear() contain an infinite loop that continuously tries to set the year?

What is a BV4618_I?

Hi Paul and thank you for reply.
At this stage I just want to set a 4 digits array and when this is done to go to the next one what will be a 2 digits array. The main project will have 4 main settings zones. I mean when you press A will be able to set the date/time. When you press B or C to set maximum temperature etc.
The bv4618_i is the i2c library for the byvac 4618 lcd + 4x4 keypad i2c controller.
Thank you

You don't need a clock.

Paul, tell him.

Jr. Member. I'm allowed to make jokes now.

No problem.
Them arrays can be usef for any settings anyway
I got the first array printed in serial but I never got the second one.
can i have some help on switch the cases? i don`t really know how to make them so ..

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'){
        SetTheCLock
      }
//  setYear();
//  setMonth();
//  setDay();
//  setHour();
//  setMinute();
}
void setYear(){
  while (1){ // do forever
    if(di.keys()){
      char key=di.key();
      if(key > 9) key+='A'-10;
      else key+='0';
      year[a] = key;
       a++;
      if (a == 4){
      Serial.println(year);
      }
    }
  }
}
void setMonth(){
  while (1){ // do forever
    if(di.keys()){
      char key=di.key();
      if(key > 9) key+='A'-10;
      else key+='0';
      month[m] = key;
       m++;
      if (m == 2){
      Serial.println(month);
      }
    }
  }
}
void setDay(){
  while (1){ // do forever
    if(di.keys()){
      char key=di.key();
      if(key > 9) key+='A'-10;
      else key+='0';
      day[d] = key;
       d++;
      if (d == 2){
      Serial.println(day);
      }
    }
  }
}
void setHour(){
  while (1){ // do forever
    if(di.keys()){
      char key=di.key();
      if(key > 9) key+='A'-10;
      else key+='0';
      hour[h] = key;
       h++;
      if (h == 2){
      Serial.println(hour);
      }
    }
  }
}
void setMinute(){
  while (1){ // do forever
    if(di.keys()){
      char key=di.key();
      if(key > 9) key+='A'-10;
      else key+='0';
      minute[mi] = key;
       mi++;
      if (mi == 2){
      Serial.println(day);
      }
    }
  }
}
can i have some help on switch the cases?

You have too many other problems to be worried about that, yet. You should start by putting every { on a new line, and using Tools + Auto Format. Well, at least you should try. Then, perhaps, you'd see that the setYear(), etc. functions are define IN the loop() function. Which clearly is not allowed.

well i have them on the loop just for testing the output.

well i have them on the loop just for testing the output.

On the loop()?

Calling a function from in loop() is perfectly reasonable. Defining a function INSIDE loop() is not.

thank you for reply Paul
you mean defining my keypad in the loop?
i was trying all the ways and did not work so and my knowledge about c++ are minimal. to create a function i have to read 2 days on internet thats the reason why im here you see
i was trying everything inlude the vectors like:

for(a=0;a<=4;a++)
{do{
year[a] = key;
}while(!key);
Serial.println(year);
}
for(m=0;m<=2;m++)
{do{
day[m] = key;
}while(!key);
Serial.println(day);
}
}
did not worked out for me so
what you will do on my case?

 for(a=0;a<=4;a++)
{do{
     year[a] = key;
}while(!key);
Serial.println(year);
}

"year" is an array with four elements - it does not have an element [4].

there is defined at the begining
char year[4];

Yes, that's a declaration of an array with four elements.
The valid indices of that array are 0, 1, 2, 3.
4 is not a valid index of that array.

yes and i`m confused now :slight_smile:
you mean for(a=0;a<=3;a++)
can you example that for me please?
thank you for the reply, i have a beer for you on Dublin :slight_smile:

More usually for(a = 0; a < 4; a++)

yes and when i press 1 2 3 4 the output is the output is this:
1
11
111
1111
1111
1111
1111
1111
2111
2211
2221
2222
3222
3322
3332
3333
3333
3333
3333
3333
4333
4433
4443
4444

and when i use :
year[a] = key;
a++;
if (a == 4){
Serial.println(year);
the output will be 1234 but i don`t know how to swap to set month you see

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

That should be something like:

   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
   }

and the beer goes toooo Seattle

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

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

any bit of help please?

You should use http://snippets-r-us.com to get answers about your snippet.

#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