Boa Tarde,

Pessoal estou com um problema. Fiz um menu para navegar através do keypad 4x4, a seleção funciona normal. Mas quando entro no item de um menu para setar um valor, o keypad não retorna nada.

Alguém poderia me dar uma luz, segue o fonte.

Obrigado

#include <LiquidCrystal.h>
#include <Keypad.h>


LiquidCrystal lcd(2, 3, 4, 5, 6, 7);


int currentMenuItem = 0;
int lastState = 0;

const byte LINHAS = 4;
const byte COLUNAS = 4;
char teclas[LINHAS][COLUNAS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0',':','D'}
};

char tecla[LINHAS][COLUNAS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0',':','D'}
};

byte pinoColuna[COLUNAS] = {22,23,24,25};
byte pinoLinha[LINHAS] = {26,27,28,29};
int count=0;
char letra;

Keypad keypad = Keypad( makeKeymap(teclas), pinoLinha, pinoColuna, LINHAS, COLUNAS );

void setup() {

lcd.begin(20, 4);

clearPrintTitle();
}

void loop() {

mainMenu();

}

void mainMenu() {

int state = 0;

lcd.setCursor(0,0);
letra = keypad.getKey();


if (letra == 'A') {
//UP
state = 1;
} else if (letra == 'B') {
//Down
state = 2;
} else if (letra == '*'){
//Select
state = 3;
}

if (currentMenuItem < 0 || currentMenuItem > 4) {
currentMenuItem = 0;
}


if (state != lastState) {
if (state == 1) {
//If Up
currentMenuItem = currentMenuItem - 1;
displayMenu(currentMenuItem);
} else if (state == 2) {
//If Down
currentMenuItem = currentMenuItem + 1;
displayMenu(currentMenuItem);
} else if (state == 3) {
//If Selected
selectMenu(currentMenuItem);
}

lastState = state;
}

delay(5);
}


void displayMenu(int x) {
switch (x) {
case 1:
clearPrintTitle();
lcd.print ("-> Temperatura");
break;
case 2:
clearPrintTitle();
lcd.print ("-> Tempo");
break;
}
}


void clearPrintTitle() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" REVELADOR ");
lcd.setCursor(0,1);
}


void selectMenu(int x) {

switch (x) {
case 1:
clearPrintTitle();
lcd.print ("Seta temperatura");

lcd.setCursor(0,2);
lcd.print(letra);

break;

}
}

Exibições: 759

Responder esta

Respostas a este tópico

Alguém?

Obrigado

Essa ta difícil

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço