Problem with my arrays
code: [select]
void alarmtimes (){
int alarmhour[12]={0};
int alarmminute[12]={0};
if (dy==1){ //monday
alarmday=1;
alarmhour[12]={8,8,9,9,10,10,10,11,12,14,15,16};
alarmminute[12]={0,40,0,40,0,20,50,10,0,30,10,10};
}
else if (dy==2){ //tuesday
alarmday =2;
alarmhour[12]={7,7,8,9,9,10,10,11,11,13,16,17};
alarmminute[12]={0,40,20,0,45,12,13,0,55,0,0,10};
}
else if (dy==3){ //wednesday
alarmday = 3;
alarmhour[12] ={};
alarmminute[12]={};
}
else if(dy==4){ //thursday
alarmday = 4;
alarmhour[12] ={};
alarmminute[12]={};
}
else if(dy==5){ //friday
alarmday = 5;
alarmhour[12] ={};
alarmminute[12]={};
}
else if(dy==6){ //saturday
alarmday = 6;
alarmhour[12] ={};
alarmminute[12]={};
}
else{
}
if(dy == alarmday){
int km = 0;
if (alarmhour[km]==hr&&alarmminute[km]==alarmminute){
ringalarm();}
km++;
}
}
exit status 1
cannot convert '<brace-enclosed initializer list>' 'int' in assignment
i trying declare arrays 12 objects, change values inside function.
i have populated times monday , tuesday.
it's alarm clock supports different alarm times during different days.
please advise on how best this
you can't do
int alarmhour[12]={0};
int alarmminute[12]={0};
and later do
alarmhour[12]={8,8,9,9,10,10,10,11,12,14,15,16};
initialization of array works @ declaration time (the compiler work set memory in right way)
so either do
// let compiler calculate size of array based on declaration
int alarmhour[]={8,8,9,9,10,10,10,11,12,14,15,16};
int alarmminute[]={0,40,0,40,0,20,50,10,0,30,10,10};
at declaration time
or need set them manually such
int alarmhour[12];
int alarmminute[12];
and initialize them later
...
alarmhour[0] = 8;
alarmhour[1] = 8;
....
int alarmhour[12]={0};
int alarmminute[12]={0};
and later do
alarmhour[12]={8,8,9,9,10,10,10,11,12,14,15,16};
initialization of array works @ declaration time (the compiler work set memory in right way)
so either do
// let compiler calculate size of array based on declaration
int alarmhour[]={8,8,9,9,10,10,10,11,12,14,15,16};
int alarmminute[]={0,40,0,40,0,20,50,10,0,30,10,10};
at declaration time
or need set them manually such
int alarmhour[12];
int alarmminute[12];
and initialize them later
...
alarmhour[0] = 8;
alarmhour[1] = 8;
....
Arduino Forum > Using Arduino > Programming Questions > Problem with my arrays
arduino
Comments
Post a Comment