Since I started this menu project, even
if I have to upgrade to a Arduino Mega to get it working, I find it a
fascinating challenge. In the last post I defined the main menu
structure. In this post I would like to change the first values using
the menu.
Last night I got some very helpful comments on the last post and I will have a look at some different approaches to do this menu. I have already a third post prepared, for the current version to add some sub menu's which I will finish not to leave a gap in the structure. For small projects which can live with a small menu, the current version is a definite option. However, for larger projects requiring a large menu structure, this version uses up to much of the microprocessors memory. For now, lets have a look at part two of the current version:
Last night I got some very helpful comments on the last post and I will have a look at some different approaches to do this menu. I have already a third post prepared, for the current version to add some sub menu's which I will finish not to leave a gap in the structure. For small projects which can live with a small menu, the current version is a definite option. However, for larger projects requiring a large menu structure, this version uses up to much of the microprocessors memory. For now, lets have a look at part two of the current version:
We jump in at the top of the menu
sketch and add some variables which I take direct from the Room
Management System sketch to make implementation of the menu at a
later point more easy.
const int btnNone = 0;
//assignment for no button pressed
const byte arrowRight = B01111110; //defining a special char to be printed
//on the lcd (right arrow)
//a list with special characters and it's
//binary definitions can be found in the
//Arduino Cookbook
int menuOption = 0;
//menuOption counter
int menuOptions = 19;
//available options
//The below variables are taken from
the Room Management
//sketch and representing the default
setup. This are also
//the values, the system will fall back
to if something goes
//wrong like a power loss or even a
system update.
//>>>>>>addition
start<<<<<<<<<<<<
/////////////////////////////////////////////////////////
//////////////var from
RMU/////////////////////
int sensitivity = 500;
//var holding the over all responsiveness
//of the RMU representing a time delay
//between 0 and 1000 milliseconds at the
//of the main loop
int photoCellCutOff = 280;
//The affected room lights switch on when
//the photocell reading goes below the set
//value
int photoOutsideOff = 260;
//The outside light will switch on when
//the photocell reading goes below this
//value
//The following values representing
delay times when lights switch
//off after the last detection off
movement in a room in milliseconds
long dBed1 = 60000;
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//>>>>>>addition
end<<<<<<<<<<<<
void setup() {
lcd.begin(16, 2); //start lcd with 16 col and 2 row
Now we are going down to the end of our
selectMenu() function.
if(menuOption == 19){
//if menuOption is 19
lcd.clear();
//clear lcd
lcd.print("AC 4:");
//print menu point
lcd.setCursor(15, 0);
//set cursor to the end of the row
lcd.write(arrowRight);
//print right arrow to indicate
//existing sub menus
}
}
//>>>>>>>>>>>>addition
start here<<<<<<<<<<<<<<<<<<<<<
if(button == btnSelect){ //if the button Select was pressed
if(menuOption == 1){
//checking the menu option
get_Timer("Set Sens",
sensitivity, 0, 1000); //function to change and set the
//system sensitivity
return;
//return to main loop
}
if(menuOption == 2){
//check the menu option
get_Timer("Set photo cut
R", photoCellCutOff, 0, 1024); //function call
return;
//return to main loop
}
if(menuOption == 3){
//left empty cause not implemented yet
return;
}
if(menuOption == 4){
//check the menu option
get_Timer("Set photo cut
O", photoOutsideOff, 0, 1024); //function call
return;
//return to main loop
}
if(menuOption == 5){
//left empty cause not implemented yet
return;
}
//>>>>>>>>>>>>addition
ends here<<<<<<<<<<<<<<<<<<<<
}
}
That wasn't that hard to do. While we
are still in the while-loop, we are checking if at any point the
button “Select” was pressed. If yes, we check at which menu point
(menuOption) and call a function which will update the value
accordingly.
The function get_Timer needs a few
values to be passed on to make it a bit more universal usable. The
first value is the string we want to print as update message. Second,
we add the variable holding the value we want to change. The next two
values giving the range in which the function is allowed to change.
Lets have a closer look. We can start
adding the function right at the end of selectMenu() function.
int get_Timer(char timerText[], int
reading, int startVal, int maxCount){
int value = reading;
//passing the var to change for
processing
int button = 0;
//reset the button value
lcd.clear();
//clear the screen
lcd.print(timerText);
//print the passed on text
lcd.setCursor(0, 1);
//set cursor to bottom row
lcd.print(value);
//print value to be changed
while(button != btnSelect){
//keep an eye on select button
button = read_buttons();
//check for buttons pressed
if(button == btnSearch){
//if button search is pressed
if(value > startVal &&
value < maxCount){ //check if the value is within
//allowed range
value++;
//add 1 with every cycle
}
if(value >= maxCount){
//if value reaches the max
value = startVal;
//we start over at minimum
value++;
//add 1 with every cycle
}
lcd.setCursor(0, 1);
//set cursor to bottom row
lcd.print(value);
//print updated value
lcd.print(" ");
//prepare screen for next
value
}
}
//The following statement check where
the variable to process
//came from and give it back to it's
origin
if(menuOption == 1 && value
!= reading){
sensitivity = value;
}
if(menuOption == 2 && value
!= reading){
photoCellCutOff = value;
}
if(menuOption == 4 && value
!= reading){
photoOutsideOff = value;
}
return value;
}
In the next post we start with sub
menu's and a couple of more functions to process the changes.
No comments:
Post a Comment