Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SubMenuItem.h>
- #include <SubMenu.h>
- #include <MenuItem.h>
- #include <Menu.h>
- //initialize menu
- int seque;
- Menu menu = Menu(menuUsed,menuChanged);
- //initialize menuitems
- MenuItem menuItem1 = MenuItem();
- SubMenu subMenu1 = SubMenu(menuChanged);
- SubMenuItem subMenu1Item1 = SubMenuItem();
- SubMenuItem subMenu1Item2 = SubMenuItem();
- SubMenuItem subMenu1Item3 = SubMenuItem();
- MenuItem menuItem2 = MenuItem();
- SubMenu subMenu2 = SubMenu(menuChanged);
- SubMenuItem subMenu2Item1 = SubMenuItem();
- SubMenuItem subMenu2Item2 = SubMenuItem();
- SubMenuItem subMenu2Item3 = SubMenuItem();
- MenuItem menuItem3 = MenuItem();
- SubMenu subMenu3 = SubMenu(menuChanged);
- SubMenuItem subMenu3Item1 = SubMenuItem();
- SubMenuItem subMenu3Item2 = SubMenuItem();
- SubMenuItem subMenu3Item3 = SubMenuItem();
- //-------------------------------------------------------------------------
- void setup(){
- Serial.begin(9600);
- //configure menu
- menu.addMenuItem(menuItem1);
- subMenu1.addSubMenuItem(subMenu1Item1);
- subMenu1.addSubMenuItem(subMenu1Item2);
- subMenu1.addSubMenuItem(subMenu1Item3);
- menu.addMenuItem(menuItem2);
- subMenu2.addSubMenuItem(subMenu2Item1);
- subMenu2.addSubMenuItem(subMenu2Item2);
- subMenu2.addSubMenuItem(subMenu2Item3);
- menu.addMenuItem(menuItem3);
- subMenu3.addSubMenuItem(subMenu3Item1);
- subMenu3.addSubMenuItem(subMenu3Item2);
- subMenu3.addSubMenuItem(subMenu3Item3);
- menu.select(0);
- subMenu1.select(0);
- }
- //---------------------------------------------------------------------------
- void loop(){
- if (Serial.available()){
- switch (Serial.read()){
- case 'w':
- if(menu.isCurrentSubMenu())
- {
- subMenu1.down(); //set index closer to 0
- }
- break;
- case 's':
- if (menu.isCurrentSubMenu()){
- subMenu1.up(); //set index closer to maximum
- }
- break;
- case 'd':
- seque--;
- if (seque > 3) seque = 3;
- menu.down();
- break;
- case 'u':
- seque++;
- if (seque < 0) seque = 0;
- menu.up();
- break;
- case ' ':
- menu.use();
- break;
- case '0':
- seque = 0;
- menu.select(0);
- break;
- case '1':
- seque = 1;
- menu.select(1);
- break;
- case '2':
- seque = 2;
- menu.select(2);
- break;
- case '3':
- subMenu1.up();
- break;
- case '4':
- subMenu1.down();
- break;
- case '5':
- subMenu2.up();
- break;
- case '6':
- subMenu2.down();
- break;
- case '7':
- subMenu3.up();
- break;
- case '8':
- subMenu3.down();
- break;
- }
- }
- }
- //---------------------------------------------------------------------------
- void menuChanged(ItemChangeEvent event){
- // Serial.println("menuChanged");
- int xpto = menu.isCurrentSubMenu();
- Serial.println(xpto);
- if( event == &menuItem1 )
- {
- Serial.println("\tmenu 0"); //user feedback
- }
- if( event == &menuItem2 )
- {
- Serial.println("\tmenu 1 "); //user feedback
- }
- if( event == &menuItem3 )
- {
- Serial.println("\tmenu 2"); //user feedback
- }
- if (seque == 0)
- {
- if( event == &subMenu1Item1 )
- {
- Serial.println("\tsub Menu 0 "); //user feedback
- }
- if( event == &subMenu1Item2 )
- {
- Serial.println("\tsub Menu 1"); //user feedback
- }
- if( event == &subMenu1Item3 )
- {
- Serial.println("\tsub Menu 2 "); //user feedback
- }
- }
- }
- //---------------------------------------------------------------------------
- void menuUsed(ItemUseEvent event)
- {
- Serial.println("menuUsed");
- if( event == &menuItem1 )
- {
- Serial.println("\tmenuItem1 used"); //user feedback
- }else
- if( event == &subMenu1Item1 )
- {
- Serial.println("\tsubMenuItem1 used"); //user feedback
- }else
- if( event == &subMenu1Item2 )
- {
- Serial.println("\tsubMenuItem2 used"); //user feedback
- }else
- if( event == &subMenu1Item3 )
- {
- Serial.println("\tsubMenuItem3 used"); //user feedback
- }else
- if( event == &menuItem3 )
- {
- Serial.println("\tmenuItem3 used"); //user feedback
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement