Menu Library for Arduino
Author:  Alexander Brevig
Contact: alexanderbrevig@gmail.com

<<under construction>>


Navigation


Current version

1.0 2009-04-22: Initial Release
A newer Version can be found on Wiring: https://github.com/WiringProject/Wiring/blob/master/framework/libraries/MenuBackend/MenuBackend.h


History

1.0 2009-04-22: Initial Release


Description

Menu is a library for the Arduino.

It's created to simplify the making and managing of menus.


Download, install and import

Download here: Attach:Menu.zip

Put the Menu folder in "hardware\libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->Menu".


Creation

//under construction


Functions

//under construction


Example

  1. #include <SubMenuItem.h>
  2. #include <SubMenu.h>
  3. #include <MenuItem.h>
  4. #include <Menu.h>
  5. //initialize menu
  6. Menu menu = Menu(menuUsed,menuChanged);
  7. //initialize menuitems
  8.   MenuItem menuItem1 = MenuItem();
  9.   MenuItem menuItemWithSubmenu = MenuItem();
  10.     SubMenu subMenu = SubMenu(menuChanged);
  11.       SubMenuItem subMenuItem1 = SubMenuItem();
  12.       SubMenuItem subMenuItem2 = SubMenuItem();
  13.       SubMenuItem subMenuItem3 = SubMenuItem();
  14.   MenuItem menuItem3 = MenuItem();
  15.  
  16. void setup(){
  17.   Serial.begin(9600);
  18.  
  19.   //configure menu
  20.   menu.addMenuItem(menuItem1);
  21.   menu.addMenuItem(menuItemWithSubmenu);
  22.     menuItemWithSubmenu.addSubMenu(subMenu);
  23.       subMenu.addSubMenuItem(subMenuItem1);
  24.       subMenu.addSubMenuItem(subMenuItem2);
  25.       subMenu.addSubMenuItem(subMenuItem3);
  26.   menu.addMenuItem(menuItem3);
  27.  
  28.   menu.select(0);
  29.   subMenu.select(0);
  30. }
  31. void loop(){
  32.   if (Serial.available()){
  33.     switch (Serial.read()){  
  34.       case 'w':
  35.         if (menu.isCurrentSubMenu()){
  36.           subMenu.down(); //set index closer to 0
  37.         }
  38.         break;
  39.       case 's':
  40.         if (menu.isCurrentSubMenu()){
  41.           subMenu.up(); //set index closer to maximum
  42.         }
  43.         break;
  44.       case 'a':
  45.         menu.down();
  46.         break;
  47.       case 'd':
  48.         menu.up();
  49.         break;
  50.       case ' ':
  51.         menu.use();
  52.         break;
  53.       case '0':
  54.         menu.select(0);
  55.         break;
  56.       case '1':
  57.         menu.select(1);
  58.         break;
  59.       case '2':
  60.         menu.select(2);
  61.         break;
  62.     }
  63.   }
  64. }
  65.  
  66. void menuChanged(ItemChangeEvent event){
  67.   Serial.println("menuChanged");
  68.   if( event == &menuItem1 ){
  69.     Serial.println("\tmenuItem1 selected"); //user feedback
  70.   }else if( event == &menuItemWithSubmenu ){
  71.     Serial.println("\tmenuItemWithSubmenu selected"); //user feedback
  72.   }else if( event == &subMenuItem1 ){
  73.     Serial.println("\tsubMenuItem1 selected"); //user feedback
  74.   }else if( event == &subMenuItem2 ){
  75.     Serial.println("\tsubMenuItem2 selected"); //user feedback
  76.   }else if( event == &subMenuItem3 ){
  77.     Serial.println("\tsubMenuItem3 selected"); //user feedback
  78.   }else if( event == &menuItem3 ){
  79.     Serial.println("\tmenuItem3 selected"); //user feedback
  80.   }
  81. }
  82.  
  83. void menuUsed(ItemUseEvent event){
  84.   Serial.println("menuUsed");
  85.   if( event == &menuItem1 ){
  86.     Serial.println("\tmenuItem1 used"); //user feedback
  87.   }else if( event == &subMenuItem1 ){
  88.     Serial.println("\tsubMenuItem1 used"); //user feedback
  89.   }else if( event == &subMenuItem2 ){
  90.     Serial.println("\tsubMenuItem2 used"); //user feedback
  91.   }else if( event == &subMenuItem3 ){
  92.     Serial.println("\tsubMenuItem3 used"); //user feedback
  93.   }else if( event == &menuItem3 ){
  94.     Serial.println("\tmenuItem3 used"); //user feedback
  95.   }
  96. }
  97.  


FAQ


Information about this page

Part of AlphaBeta Libraries.
Last Modified: February 03, 2012, at 11:25 AM
By: Niggoh

Share