Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //init var(s)
- char menu_pos = 0; //Our Current Position
- char menu_end = 10; //Our Last Position
- char menu_sel = 0; //Our Selected Item
- //...
- void LoadMenu (pos)
- {
- char done = 0; //Loop until new btn pressed holder
- char state = 0; //Button Pressed State
- switch(pos) //Switch based on the POS variable
- {
- case 0:
- PrintLCD(">Item 1",LINE1); //Show user MENU(n)
- PrintLCD("Item 2",LINE2); //Show user Menu(n+1)
- while(!done) //Loop until new POS selected (done = 1)
- done = chk_btn;
- if(done == 2) //or new ITEM selected (done == 2)
- ITEM_1_Function_Call(); //Do Something for that ITEM
- break; //BREAK :)
- case 1:
- PrintLCD("Item 1",LINE1);
- PrintLCD(">Item 2",LINE2);
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_2_Function_Call();
- break;
- case 2:
- PrintLCD(">Item 2",LINE1);
- PrintLCD("Item 3",LINE2);
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_2_Function_Call();
- break;
- case 3:
- PrintLCD("Item 2",LINE1);
- PrintLCD(">Item 3",LINE2);
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_3_Function_Call();
- break;
- case 4:
- PrintLCD(">Item 3",LINE1);
- PrintLCD("Item 4",LINE2);
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_3_Function_Call();
- break;
- case 5:
- PrintLCD("Item 3",LINE1);
- PrintLCD(">Item 4",LINE2);
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_4_Function_Call();
- break;
- case 6:
- PrintLCD(">Item 4",LINE1);
- PrintLCD("Item 5",LINE2);
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_4_Function_Call();
- break;
- case 7:
- PrintLCD("Item 4",LINE1);
- PrintLCD(">Item 5",LINE2);;
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_5_Function_Call();
- break;
- case 8:
- PrintLCD(">Item 5",LINE1);
- PrintLCD("Item 6",LINE2);;
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_5_Function_Call();
- break;
- case 9:
- PrintLCD("Item 5",LINE1);
- PrintLCD(">Item 6",LINE2);;
- while(!done)
- done = chk_btn;
- if(done == 2)
- ITEM_6_Function_Call();
- break;
- }
- }
- //...
- char chk_button (char ITEM)
- {
- char old_pos = menu_pos; //Test Variable to determine if new POS is selected
- char old_sel = menu_sel; //Test Variable to determine if new ITEM is selected
- if(up_button == pressed) //UP PRESSED = TRUE then INCREMENT MENU_POS var
- if(menu_pos < menu_end) menu_pos++;
- if(dn_button == pressed) //DOWN PRESSED = TRUE then DECREMENT MENU_POS var
- if(menu_pos > 0) menu_pos--;
- if(sel_button == pressed) //ENTER/SEL PRESSED = TRUE then SELECTED = ITEM
- menu_sel = ITEM;
- if(menu_pos != old_pos) //If new POS return a 1
- return 1;
- if(menu_sel != old_sel) //If new SELECTION return a 2
- return 2;
- return 0; //NOTHING NEW RETURN 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement