Advertisement
AtomSoft

Menu Example

Aug 23rd, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.03 KB | None | 0 0
  1. //init var(s)
  2. char menu_pos = 0;    //Our Current Position
  3. char menu_end = 10;   //Our Last Position
  4. char menu_sel = 0;    //Our Selected Item
  5.  
  6. //...
  7.  
  8. void LoadMenu (pos)
  9. {
  10.   char done = 0;            //Loop until new btn pressed holder
  11.   char state = 0;           //Button Pressed State
  12.  
  13.   switch(pos)               //Switch based on the POS variable
  14.   {
  15.     case 0:
  16.       PrintLCD(">Item 1",LINE1); //Show user MENU(n)
  17.       PrintLCD("Item 2",LINE2);  //Show user Menu(n+1)
  18.       while(!done)               //Loop until new POS selected (done = 1)
  19.         done = chk_btn;          
  20.        
  21.       if(done == 2)              //or new ITEM selected (done == 2)
  22.         ITEM_1_Function_Call();  //Do Something for that ITEM
  23.      
  24.       break;                     //BREAK :)
  25.     case 1:
  26.       PrintLCD("Item 1",LINE1);
  27.       PrintLCD(">Item 2",LINE2);
  28.       while(!done)
  29.         done = chk_btn;
  30.        
  31.       if(done == 2)
  32.         ITEM_2_Function_Call();
  33.      
  34.       break;
  35.     case 2:
  36.       PrintLCD(">Item 2",LINE1);
  37.       PrintLCD("Item 3",LINE2);
  38.       while(!done)
  39.         done = chk_btn;
  40.        
  41.       if(done == 2)
  42.         ITEM_2_Function_Call();
  43.      
  44.       break;
  45.     case 3:
  46.       PrintLCD("Item 2",LINE1);
  47.       PrintLCD(">Item 3",LINE2);
  48.       while(!done)
  49.         done = chk_btn;
  50.        
  51.       if(done == 2)
  52.         ITEM_3_Function_Call();
  53.      
  54.       break;
  55.     case 4:
  56.       PrintLCD(">Item 3",LINE1);
  57.       PrintLCD("Item 4",LINE2);
  58.       while(!done)
  59.         done = chk_btn;
  60.        
  61.       if(done == 2)
  62.         ITEM_3_Function_Call();
  63.      
  64.       break;
  65.     case 5:
  66.       PrintLCD("Item 3",LINE1);
  67.       PrintLCD(">Item 4",LINE2);
  68.       while(!done)
  69.         done = chk_btn;
  70.        
  71.       if(done == 2)
  72.         ITEM_4_Function_Call();
  73.      
  74.       break;
  75.     case 6:
  76.       PrintLCD(">Item 4",LINE1);
  77.       PrintLCD("Item 5",LINE2);
  78.       while(!done)
  79.         done = chk_btn;
  80.        
  81.       if(done == 2)
  82.         ITEM_4_Function_Call();
  83.      
  84.       break;
  85.     case 7:
  86.       PrintLCD("Item 4",LINE1);
  87.       PrintLCD(">Item 5",LINE2);;
  88.       while(!done)
  89.         done = chk_btn;
  90.        
  91.       if(done == 2)
  92.         ITEM_5_Function_Call();
  93.      
  94.       break;
  95.     case 8:
  96.       PrintLCD(">Item 5",LINE1);
  97.       PrintLCD("Item 6",LINE2);;
  98.       while(!done)
  99.         done = chk_btn;
  100.        
  101.       if(done == 2)
  102.         ITEM_5_Function_Call();
  103.      
  104.       break;
  105.     case 9:
  106.       PrintLCD("Item 5",LINE1);
  107.       PrintLCD(">Item 6",LINE2);;
  108.       while(!done)
  109.         done = chk_btn;
  110.        
  111.       if(done == 2)
  112.         ITEM_6_Function_Call();
  113.      
  114.       break;
  115.   }
  116. }
  117.  
  118. //...
  119.  
  120. char chk_button (char ITEM)
  121. {
  122.   char old_pos = menu_pos;      //Test Variable to determine if new POS is selected
  123.   char old_sel = menu_sel;      //Test Variable to determine if new ITEM is selected
  124.  
  125.   if(up_button == pressed)      //UP PRESSED = TRUE then INCREMENT MENU_POS var
  126.     if(menu_pos < menu_end) menu_pos++;
  127.  
  128.   if(dn_button == pressed)      //DOWN PRESSED = TRUE then DECREMENT MENU_POS var
  129.     if(menu_pos > 0) menu_pos--;
  130.    
  131.   if(sel_button == pressed)     //ENTER/SEL PRESSED = TRUE then SELECTED = ITEM
  132.     menu_sel = ITEM;
  133.    
  134.   if(menu_pos != old_pos)       //If new POS return a 1
  135.     return 1;
  136.    
  137.   if(menu_sel != old_sel)       //If new SELECTION return a 2
  138.     return 2;
  139.        
  140.   return 0;                     //NOTHING NEW RETURN 0
  141.    
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement