Boa noite galera, estou tendo um problema em imprimir alguns caracteres, o teclado esta correto, ate por que em 1 dos códigos ele imprime todos sem nenhum erro, mas quando utilizo o segundo ele imprimi uma figura estranha, sendo que nao tem nem na tabela de caracteres especias.
aqui é o código que imprime todos os caracteres do mapa sem nenhum erro, o segundo vou postar abaixo por que excedeu o limite de caracteres hehe
/*
Keypad sketch
prints the key pressed on a keypad to the serial port
*/
#include <LiquidCrystal.h>
#include<stdlib.h>
LiquidCrystal lcd(76,77,14,15,16,17);
const int numRows = 5; // number of rows in the keypad
const int numCols = 3; // number of columns
const int debounceTime = 100; // number of milliseconds for switch to be stable
const int debounce = 50;
const int backlight = 70;
unsigned char key;
char valor[5];//isto é na realidade um ponteiro...
//char valor_anterior[4];
//char *ponteiro_valor = &valor[0]; //isto está errado...
char valor_index = 0;
String menu = "aplicacao";
String str1 = " temperatura";
String str2 = " umidade ";
String str3 = " irrigacao";
String str4 = " luminosidade";
unsigned int inc=0;
// keymap defines the character returned when the corresponding key is pressed
const char keymap[numRows][numCols] = {
{ '1', '2', '3' } ,
{ '4', '5', '6' } ,
{ '7', '8', '9' } ,
{ 'F', '0', 'T' } ,
{ 'E', '.', 'V'} ,
};
// this array determines the pins used for rows and columns
const int rowPins[numRows] = { 81,82,83,84,85 }; // Rows 0 through 3
const int colPins[numCols] = { 78,79,80 }; // Columns 0 through 2
void setup(){
pinMode (backlight, OUTPUT);
digitalWrite (backlight,HIGH);
lcd.begin (16,2);
valor[4] = '\0';//terminar a string.
for (int row = 0; row < numRows; row++)
{
pinMode(rowPins[row],OUTPUT); // Set row pins as input
digitalWrite(rowPins[row],HIGH); // turn on Pull-ups
}
for (int column = 0; column < numCols; column++)
{
pinMode(colPins[column],INPUT); // Set column pins as outputs for writing
digitalWrite(colPins[column],LOW); // Make all columns inactive
}
}
void loop(){
key = getKey();
if( key == 'F' && key != 0 || key == 'T' && key != 0 ){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("selecao");
valor_index = 0;
valor = {};
// void Menu();
delay (1000);
lcd.clear();}
//delay(500);
else if( key != 'F' && key != 0 || key != 'T' && key != 0 ){
valor[valor_index++] = key ;
if (valor_index <= 5 ) { //indice 4 é o terminador de string, logo apenas vais imprimir 4 digitos.
lcd.clear();
lcd.print(valor);
delay(1000);
if (valor_index == 4 ){
delay(1000);
lcd.clear();
valor_index = 0;
valor = {};
}
}
delay(100);
}//lcd.clear();
//lcd.print("teste");
}
// returns with the key pressed, or 0 if no key is pressed
char getKey(){
char key = 0;
delay(100);// 0 indicates no key pressed
for(int row = 0; row < numRows; row++){
digitalWrite(rowPins[row],LOW);// Activate the current column.
for(int column = 0; column < numCols; column++){ // Scan all rows for a key press.
if(digitalRead(colPins[column]) == LOW){ // Is a key pressed?
//boolean debounce(int pin);
delay(debounce); // debounce
while(digitalRead(colPins[column]) == LOW); // wait for key to be released
key = keymap[row][column];
//delay(60);// Remember which key was pressed.
}
}
digitalWrite(rowPins[row],HIGH); // De-activate the current column.
}
return key; // returns the key pressed or 0 if none
}
void Menu(){
if ( key == 'F'){
inc +=1;
void submenu();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(menu);
delay (1000);
}
if (key == 'T'){
inc -=1;
void submenu();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(menu);
delay (1000);
}
else{}
return;
}
void submenu(){
if ( inc == -1){
inc = 4;
menu = str4;
return;}
else if ( inc == 1 ){ // seleciona temperatura
menu = str1;
return;
}
else if ( inc == 2){ // seleciona umidade
menu = str2;
return;
}
else if ( inc == 3){ // seleciona irrigação
menu = str3;
return;
}
else if ( inc == 4){ // seleciona luminosidade
menu = str4;
return;
}
else ( menu == 5);{ // imprime aplicação
inc = 0;
menu = "aplicacao";
return;
}
return;
}