Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://labdegaragem.com/forum/topics/ajuda-com-menu-chocadeira
- // http://playground.arduino.cc/Code/Menu
- #include <LiquidCrystal.h>
- #include <Menu.h>
- #include <MenuItem.h>
- #include <SubMenu.h>
- #include <SubMenuItem.h>
- LiquidCrystal lcd(9, 8, 7, 6, 5, 4); //Ordem dos pinos RS EN D4 D5 D6 D7
- // Pino LCD 4 6 11 12 13 14
- //initialize menu
- Menu Choco = Menu(menuUsed,menuChanged);
- //initialize menuitems
- MenuItem ChocoItem1 = MenuItem();
- MenuItem ChocoItem2 = MenuItem();
- SubMenu ChocosubMenu = SubMenu();
- SubMenuItem ChocosubMenuItem1 = SubMenuItem();
- SubMenuItem ChocosubMenuItem2 = SubMenuItem();
- SubMenuItem ChocosubMenuItem3 = SubMenuItem();
- MenuItem ChocoItem3 = MenuItem();
- // ------------------------------ setup ----------------------------
- void setup(){
- Serial.begin(9600);
- lcd.begin(16, 2); //Inicia o LCD com dimensões 16x2(Colunas x Linhas)
- //configure menu
- Choco.addMenuItem(ChocoItem1);
- Choco.addMenuItem(ChocoItem2);
- ChocoItem2.addSubMenu(ChocosubMenu);
- ChocosubMenu.addSubMenuItem(ChocosubMenuItem1);
- ChocosubMenu.addSubMenuItem(ChocosubMenuItem2);
- ChocosubMenu.addSubMenuItem(ChocosubMenuItem3);
- Choco.addMenuItem(ChocoItem3);
- Choco.select(0);
- ChocosubMenu.select(0);
- }
- // ------------------------------ loop ----------------------------
- void loop()
- {
- // lcd.clear();// Limpa do buffer do LCD
- // lcd.setCursor(0, 0);
- // lcd.print("Imprimindo TXT");
- if (Serial.available())
- {
- switch (Serial.read())
- {
- case 'w':
- if (Choco.isCurrentSubMenu())
- {
- Serial.println("A ");
- ChocosubMenu.down(); //set index closer to 0
- }
- break;
- case 's':
- if (Choco.isCurrentSubMenu())
- {
- ChocosubMenu.up(); //set index closer to maximum
- }
- break;
- case 'a':
- Choco.down();
- break;
- case 'd':
- Choco.up();
- break;
- case ' ':
- Choco.use();
- break;
- case '0':
- Choco.select(0);
- break;
- case '1':
- Choco.select(1);
- break;
- case '2':
- Choco.select(2);
- break;
- case '3':
- ChocosubMenu.select(1);
- break;
- }
- }
- }
- // ------------------------------ menuChanged ----------------------------
- void menuChanged(ItemChangeEvent event)
- {
- // Serial.println("Chocadeira");
- if( event == &ChocoItem1 )
- {
- lcd.setCursor(0, 0);
- lcd.print("Inicio");
- Serial.println("\tNivel 1"); //user feedback
- }
- // else
- if( event == &ChocoItem2 )
- {
- Serial.println("\tNivel 2"); //user feedback
- }
- // else
- if( event == &ChocosubMenuItem1 )
- {
- Serial.println("\tNivel 3"); //user feedback
- lcd.setCursor(0, 0);
- lcd.print("Temperatura");
- }
- // else
- if( event == &ChocosubMenuItem2 )
- {
- Serial.println("\tNivel 4"); //user feedback
- }
- // else
- if( event == &ChocosubMenuItem3 )
- {
- Serial.println("\tNivel 5"); //user feedback
- }
- // else
- if( event == &ChocoItem3 )
- {
- Serial.println("\tNivel 6"); //user feedback
- }
- }
- // ------------------------------ menuUsed ----------------------------
- void menuUsed(ItemUseEvent event)
- {
- Serial.println("menuUsed");
- if( event == &ChocoItem1 )
- {
- Serial.println("\tmenuItem1 used"); //user feedback
- }
- else if( event == &ChocosubMenuItem1 )
- {
- Serial.println("\tsubMenuItem1 used"); //user feedback
- }
- else if( event == &ChocosubMenuItem2 )
- {
- Serial.println("\tsubMenuItem2 used"); //user feedback
- }
- else if( event == &ChocosubMenuItem3 )
- {
- Serial.println("\tsubMenuItem3 used"); //user feedback
- }
- else if( event == &ChocoItem3 )
- {
- Serial.println("\tmenuItem3 used"); //user feedback
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement