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);
}
}
}
}
}
}
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
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);
}
}
}
}
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.
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?
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
}
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
#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