menu.init
DESCRIPTION
Initialize the menu, and send it to LCD.
SYNTAX
menu.init(char, sizeof, lcd_device);
PARAMETERS
Arrow Character
Its the character you like to have on your display, to point where the cursor is.
Size of Array
You must pass the size of the Array.
Example sizeof(menuOption));
Device to send menu to
On U1 model most likely you will send it to 'lcd'
RETURNS
none.
EXAMPLE #1.
#include
#include
InvIoT_U1 lcd(A0,A1); aIoTMenu menu; //Create menu type aIoTMenu void VOID(){} MENU menuOptions[]={ //All the items in array start with 0. First byte declares the Menu Group. Menu Group 0 is the root menu. {0,"Menu With SubMenus",'t',VOID,0}, // Title of this Menu. Declare with the 't'. Printed on top of LCD. {0,"Print Hello ",'f',helloWorld,0}, // run 'helloWorld' function. Its a 'f' type. Your 1st choice in the menu. Retrun to Root Menu (0) when exit 'helloWorld' function. {0,"Print test ",'f',printTest,0}, // run 'turnLedRed' function. Its a 'f' type. Your 2nd choice in the menu. Retrun to Root Menu (0) when exit 'turnLedRed' function. {255,"",' ',VOID,0}, //End of Menu. }; //********************* SETUP and LOOP ************** void setup() { menu.menu=menuOptions; //Set menuOptions array to menu menu.init(')',sizeof(menuOptions),lcd); //Initialize menu. Character to use for cursor is '>'. Everything is send to lcd } void loop() { menu.runMenu(); // in the loop run menu all the time. It checks for rotary or button action. } //********************* MENU FUNCTIONS ************** void helloWorld(){ lcd.clear(); lcd.print("Hello Menu"); delay(2000); } void printTest(){ lcd.clear(); lcd.print("test"); delay(2000); }
EXAMPLE #2. Switching Menus
#include
#include
InvIoT_U1 lcd(A0,A1); aIoTMenu menu; //Create menu type aIoTMenu void VOID(){} MENU menuOptions1[]={ {0," First Menu",'t',VOID,0}, {0,"Goto Menu #2 ",'f',gotoMenu2,}, {0,"Print Hello from #1",'f',helloWorld,0}, {255,"",' ',VOID,0}, //End of Menu. }; MENU menuOptions2[]={ {0," Second Menu",'t',VOID,0}, {0,"Goto Menu #2 ",'f',gotoMenu1,0}, {0,"Print Hello from #2",'f',helloWorld,0}, {255,"",' ',VOID,0}, //End of Menu. }; //********************* SETUP and LOOP ************** void setup() { menu.menu=menuOptions1; //Set menuOptions array to menu menu.init('*',sizeof(menuOptions1),lcd); //Initialize menu. Character to use for cursor is '>'. Everything is send to lcd } void loop() { menu.runMenu(); // in the loop run menu all the time. It checks for rotary or button action. } //********************* MENU FUNCTIONS ************** void helloWorld(){ lcd.clear(); lcd.print("Hello Menu"); delay(2000); } void gotoMenu2(){ menu.menu=menuOptions2; //Set menuOptions array to menu menu.init(')',sizeof(menuOptions2),lcd); //Initialize menu. Character to use for cursor is '>'. Everything is send to lcd } void gotoMenu1(){ menu.menu=menuOptions1; //Set menuOptions array to menu menu.init('*',sizeof(menuOptions1),lcd); //Initialize menu. Character to use for cursor is '>'. Everything is send to lcd }