Go Down

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

mariusnet

Oct 30, 2013, 12:55 pm Last Edit: Oct 30, 2013, 01:05 pm by mariusnet Reason: 1
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:
Code: [Select]

#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

PaulS

Quote
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?

The art of getting good answers lies in asking good questions.

mariusnet

#2
Oct 30, 2013, 03:00 pm Last Edit: Oct 30, 2013, 03:58 pm by mariusnet Reason: 1
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

enanthate

You don't need a clock.

Paul, tell him.

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

mariusnet

#4
Oct 30, 2013, 06:37 pm Last Edit: Oct 31, 2013, 10:25 am by mariusnet Reason: 1
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 ..
Code: [Select]

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);
      }
    }
  }
}


PaulS

Code: [Select]
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.

The art of getting good answers lies in asking good questions.

mariusnet

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

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

mariusnet

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 that`s the reason why i`m 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?

AWOL

Code: [Select]
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].

mariusnet

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

AWOL

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.

mariusnet

yes and i`m confused now :)
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 :)

AWOL

More usually
Code: [Select]
for(a = 0; a < 4; a++)

mariusnet

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

Go Up