This is an extract from an earlier part of the code.
The display has 4 lines but there are now more than 4 things to display.
My idea is to make it show 0 - 3 on one page, wait for the up/down key and display the next page, and if escape is pressed exit.
I could just write out the code for all the pages with the different start/stop values but I am sure there is a way to use the "middle" part of the code as a sub-function.
But I haven't quite got the hang of it yet.
void top_menu_function_4() //Display a list of the alarms and times.
/*
What I have learnt:
alarm_EEPROM_storage+n (where n is the alarm number) yields 0,1,2,3
0 = off
1 = Daily
2 = M-F
3 = Weekend
4 = Once
bit of informatio about the RTC alarms.
clock1.alarms[ala].hr;
clock1.alarms[ala].mnt;
clock1.alarms[ala].dow;
*/
{
byte boo;
char msg1[9];
char msg[14];
int i;
// From here down I would like to make it into a routine where I can call it with different values of 0 and 4
for (int i=0;i<4;i++)
{
lcd.setCursor(0,i);
sprintf(msg,"Alm %1d %2d:%02d ",i, clock1.alarms[i].hr, clock1.alarms[i].mnt);
boo = clock1.alarms.[i].dow);
lcd.print(msg);
if (boo == 0)
{
lcd.print("OFF");
}
if (boo == 1)
{
lcd.print("Daily");
}
if (boo == 2)
{
lcd.print("Week Day");
}
if (boo == 3)
{
lcd.print("Week End");
}
if (boo == 4)
{
lcd.print("Once");
}
}
wait_on_escape(8000);
// Insert code here to loop on certain keys so the start/end values change or exit.
return;
}
void top_menu_function_4() //Display a list of the alarms and times.
/*
What I have learnt:
alarm_EEPROM_storage+n (where n is the alarm number) yields 0,1,2,3
0 = off
1 = Daily
2 = M-F
3 = Weekend
4 = Once
bit of information about the RTC alarms.
clock1.alarms[ala].hr;
clock1.alarms[ala].mnt;
clock1.alarms[ala].dow;
*/
{
byte foo[4];
byte boo;
char msg1[9];
char msg[14];
int i;
lcd.setCursor(0,0);
for (int i=0;i<Max_alarms;i++) // the 0 and Max_alarms are now needing to be other variables.
{
// from here......
sprintf(msg,"Alm %1d %2d:%02d ",i, clock1.alarms[i].hr, clock1.alarms[i].mnt);
boo = clock1.alarms[i].dow;
lcd.print(msg);
if (boo == 0)
{
lcd.print("OFF");
}
if (boo == 1)
{
lcd.print("Daily");
}
if (boo == 2)
{
lcd.print("Week Day");
}
if (boo == 3)
{
lcd.print("Week End");
}
if (boo == 4)
{
lcd.print("Once");
}
// to here........
}
wait_on_escape(8000);
// Code in here to control start and stop numbers.
return;
}
Ok: max_alarms is how many alarms in the code. It is now 5. That is one too many to display on the screen at once.
Looking for the "From here....." "to here......"
That part needs to be a thing which I can do with 4 loops, and then call it with variable start and stop numbers for the loop controlled by code I put at the bottom.
But all the "variables" need to be passed/seen in the function thingy.
if they both work the same, the second one is slightly shorter to write, maybe if you sat down and clock it it might be a few cycles faster which can help in large/complex programs
Osgeld:
im C-tarded but I am pretty sure if you dont return it just returns null or zero (neither is == to 1)
No, it returns whatever value just happens to be in the register that return values are returned in when the function exits. Different compilers and different levels of optimization wll change what it returns.
When talking about C, I tend to say that some languages go out of the way to protect you from hanging yourself, while C will happily drive to the hardware store, get some rope, make a hangman's noose, and give it to you, saying have fun.
Osgeld:
im C-tarded but I am pretty sure if you dont return it just returns null or zero (neither is == to 1)
If the function is declared with a return type and the implementation does not explicitly return an expression that can be converted to that type, I'd expect that to cause a compilation error.
If the function is declared with a return type and the implementation does not explicitly return an expression that can be converted to that type, I'd expect that to cause a compilation error.
One would certainly hope so, but, sadly, that isn't necessarily the case. A function declared to return an int, for instance, that doesn't have a return statement still compiles, but, of course, doesn't actually return anything but garbage.