Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.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
- int botao0 = A0; // botões
- int botao1 = A1;
- int botao2 = A2;
- int botao3 = A3;
- int botao4 = A4;
- int botao5 = A5;
- int botao6 = 3;
- char bt0 = 0;
- char fbt0 = 1;
- char bt1 = 0;
- char fbt1 = 1;
- char bt2 = 0;
- char fbt2 = 1;
- char bt3 = 0;
- char fbt3 = 1;
- char bt4 = 0;
- char fbt4 = 1;
- char bt5 = 0;
- char fbt5 = 1;
- char bt6 = 0;
- char fbt6 = 1;
- char Nivel = 0;
- char Index_Nivel = 0;
- char Sub_Nivel = 0;
- char Index_Sub_Nivel = 0;
- char Pos = 1;
- byte Step = 0;
- String MeuMenu;
- //******************************* SETUP **********************************
- void setup() {
- lcd.begin(16, 2);
- lcd.clear();
- Serial.begin(9600);
- Serial.print("ok");
- pinMode(botao1, INPUT);
- digitalWrite(botao1, LOW);
- pinMode(botao0, INPUT_PULLUP); // Meunu UP
- pinMode(botao1, INPUT_PULLUP); // Meunu DOWN
- pinMode(botao2, INPUT_PULLUP); // Sub_Meunu Left
- pinMode(botao3, INPUT_PULLUP); // Sub_Meunu Right
- pinMode(botao4, INPUT_PULLUP); // Value Up
- pinMode(botao5, INPUT_PULLUP); // Value Down
- pinMode(botao6, INPUT_PULLUP); // Confirme
- DSP_Menu();
- }
- // ------------------------------- Execução ---------------------------
- void Execucao()
- {
- lcd.setCursor(0, 0);
- lcd.print(Index_Nivel+0);
- lcd.print(" ");
- lcd.print(Sub_Nivel+0);
- lcd.print(" ");
- lcd.print(Step+0);
- lcd.print(" ");
- }
- // ------------------------------- Display Menu ---------------------------
- void DSP_Menu()
- {
- lcd.clear();
- lcd.setCursor(6, 0);
- lcd.print(MeuMenu);
- lcd.setCursor(0, 1);
- lcd.print(" 0 0 0 0");
- }
- // ------------------------------- Display Index ---------------------------
- void Dsp_Index()
- {
- lcd.setCursor(6, 0);
- lcd.print(MeuMenu);
- lcd.setCursor(Pos, 1);
- lcd.print(" ");
- lcd.setCursor(Pos, 1);
- lcd.print(Step+0);
- lcd.setCursor(Pos, 1);
- lcd.blink();
- }
- // ---------------------------------- Display Sub_Menu ---------------------------
- void DSP_Sub_Menu()
- {
- lcd.setCursor(Pos, 1);
- lcd.blink();
- }
- //-------------------------- loop -------------------------------
- void loop()
- {
- //-------------------------- Menu Up -------------------------------
- bt0 = digitalRead(botao0); // Menu Up
- if ((bt0 == LOW) && (fbt0 == HIGH))
- {
- delay(30); // de-bouncing
- Nivel =Index_Nivel +1;
- Index_Nivel = Nivel;
- Sub_Nivel = 0;
- Step = 0;
- if (Nivel > 3)
- {
- Nivel = 0;
- Index_Nivel = 0;
- }
- }
- fbt0 = bt0;
- //-------------------------- Menu Down -------------------------------
- bt1 = digitalRead(botao1); // Menu Down
- if ((bt1 == LOW) && (fbt1 == HIGH))
- {
- delay(30); // de-bouncing
- Nivel = Index_Nivel -1;
- Index_Nivel = Nivel;
- Sub_Nivel = 0;
- Step = 0;
- if (Nivel < 0)
- {
- Nivel = 3;
- Index_Nivel = 3;
- }
- }
- fbt1 = bt1;
- //-------------------------- Sub_Menu Up -------------------------------
- bt2 = digitalRead(botao2); // Menu Down
- if ((bt2 == LOW) && (fbt2 == HIGH))
- {
- delay(30); // de-bouncing
- Sub_Nivel = Sub_Nivel +1;
- Step = 0;
- Dsp_Index();
- if (Sub_Nivel > 3)
- {
- Sub_Nivel = 0;
- }
- }
- fbt2 = bt2;
- //-------------------------- Sub_Menu Down -------------------------------
- bt3 = digitalRead(botao3); // Menu Down
- if ((bt3 == LOW) && (fbt3 == HIGH))
- {
- delay(30); // de-bouncing
- Sub_Nivel = Sub_Nivel - 1;
- Step = 0;
- Dsp_Index();
- if (Sub_Nivel < 0)
- {
- Sub_Nivel = 3;
- }
- }
- fbt3 = bt3;
- //-------------------------- Step_Up -------------------------------
- bt4 = digitalRead(botao4); // Menu Down
- if ((bt4 == LOW) && (fbt4 == HIGH))
- {
- delay(30); // de-bouncing
- Step = Step +1;
- if (Step > 99)
- {
- Step = 0;
- }
- Dsp_Index();
- }
- fbt4 = bt4;
- //-------------------------- Step_Down -------------------------------
- bt5 = digitalRead(botao5); // Menu Down
- if ((bt5 == LOW) && (fbt5 == HIGH))
- {
- delay(30); // de-bouncing
- Step = Step -1;
- if (Step > 99)
- {
- Step = 99;
- }
- Dsp_Index();
- }
- fbt5 = bt5;
- //-------------------------- Enter -------------------------------
- bt6 = digitalRead(botao6); // Menu Down
- if ((bt6 == LOW) && (fbt6 == HIGH))
- {
- delay(30); // de-bouncing
- Execucao();
- }
- fbt6 = bt6;
- delay(100);
- // --------------------------------- switch --------------------------
- switch (Nivel)
- {
- case 0:
- MeuMenu = "Menu 0";
- Nivel = 10;
- Dsp_Index();
- break;
- case 1:
- MeuMenu = "Menu 1";
- Nivel = 10;
- Dsp_Index();
- break;
- case 2:
- MeuMenu = "Menu 2";
- Nivel = 10;
- Dsp_Index();
- break;
- case 3:
- MeuMenu = "Menu 3";
- Nivel = 10;
- Dsp_Index();
- break;
- default:
- break;
- }
- switch (Sub_Nivel)
- {
- case 0:
- Pos = 1;
- Dsp_Index();
- break;
- case 1:
- Pos = 5;
- Dsp_Index();
- break;
- case 2:
- Pos = 9;
- Dsp_Index();
- break;
- case 3:
- Pos = 13;
- Dsp_Index();
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement