#include<string.h>
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ezBuzzer.h>
const int BUZZER_PIN = A1;
char numerotren[5];
byte numerotrenCount = 0;
bool edit = 0;
int finalValue = 0;
char numerocanal[2];
byte numerocanalCount = 0;
bool editcanal = 0;
int finalcanalValue = 0;
char ttmodo[1];
byte tipomodoCount = 0;
bool editmodo = 0;
int finalmodoValue = 0;
byte customChar[8] = {
0b00001,
0b01110,
0b10000,
0b01110,
0b10001,
0b10001,
0b10001,
0b00000
};
LiquidCrystal_I2C lcd(0x27, 16, 2);
char keys[5][8] = { //declare an array
{'E', 'F', 'G', 'H', 'I','A', '#', 'C'},
{'J', 'K', 'L', 'M', 'N','1', '2', '3'},
{'E', 'F', 'G', 'H', 'I','4', '5', '6'},
{'J', 'K', 'L', 'M', 'N','7', '8', '9'},
{'O', 'P', 'Q', 'R', 'Z','B', '0', 'D'}
};
byte rowPins[5] = {10, 11, 12, 13, A0};
byte colPins[8] = {2, 3, 4, 5, 6, 7, 8, 9};
Keypad mykeypad = Keypad(makeKeymap(keys), rowPins, colPins, 5, 8);
ezBuzzer buzzer(BUZZER_PIN); // create ezBuzzer object that attach to a pin;
long inputInt;
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.clear();
pantallaprincipal();
lcd.createChar(0, customChar);
}
void loop()
{
{
char key = mykeypad.getKey() ;
if (key){
Serial.println(key);
}
}
{
pitido();
tecladott();
modo();
canal();
numtren();
}
}
void pitido()
{
}
void pantallaprincipal()
{
lcd.setCursor(0, 0);
lcd.print(ttmodo);
lcd.setCursor(1, 0);
lcd.print(" ");
lcd.setCursor(5, 0);
lcd.print(numerocanal);
lcd.setCursor(7, 0);
lcd.print(" ");
lcd.setCursor(10, 0);
lcd.print(numerotren);
}
void tecladott()
{
char key = mykeypad.getKey() ;
if (key == 'E') //PIDO HABLAR
{
//lcd.clear();
pantallaprincipal();
lcd.setCursor(2, 1);
lcd.print("PIDO HABLAR");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'F') //ENTRO BANDA
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(1, 1);
lcd.print("ENTRO EN BANDA");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'G') //CONFORME
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(4, 1);
lcd.print("CONFORME");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'H') //CONEXION MEGAFONIA
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(3, 1);
lcd.print("MEGAFONIA>");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'I') //DETENIDO SEÑAL
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(1, 1);
lcd.print("DETENIDO");
lcd.print(" se");
lcd.setCursor(12, 1); // move cursor to (2, 0)
lcd.write((byte)0);
lcd.print("al");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'J') //INCIDENCIA
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(3, 1);
lcd.print("INCIDENCIA");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'K') //ENTRO BANDA
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(2, 1);
lcd.print("ENTRO BANDA");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'L') //AVERIA INFRAESTRUCTURA
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(1, 1);
lcd.print("AVERIA EN I.F");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'M') //DETENIDO TREN
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(1, 1);
lcd.print("DETENIDO TREN");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'N') //PIDO TREN HABLAR
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(0, 1);
lcd.print("PIDO TREN HABLAR");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'O') //SIGO MARCHA
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(2, 1);
lcd.print("SIGO MARCHA");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'P') //SER EXT
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(2, 1);
lcd.print("SERVICIO EXT");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'Q') //EMERGENCIA
{
lcd.clear();
pantallaprincipal();
lcd.setCursor(3, 1);
lcd.print("EMERGENCIA");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == 'R') //TEST
{
lcd.clear();
pantallaprincipal();
}
}
void modo()
{
char key = mykeypad.getKey();
if(key) // check if any key was pressed
Serial.print(key);
{
if(key =='A' || key == 'C' ) // if * was pressed switch to edit mode
{
lcd.clear();
if (key == 'A' || key == 'C');
{
lcd.clear();
lcd.setCursor(0,1); // set your cursor at columnt 0, row 0
//lcd.print("MODO");
editmodo= true;
lcd.setCursor(0,2); // set your cursor to second row
tipomodoCount = 0;
}
}
if(editmodo && tipomodoCount < 1 && key != 'B' && key != '#')
{
ttmodo[tipomodoCount] = key; // save key to a char array
lcd.setCursor(0,1); // set your cursor to the next position
lcd.print(ttmodo[tipomodoCount]); // print the pressed button to lcd
tipomodoCount++; // increment the array index (cursor position)
}
if( key == 'A' || key == 'C' ) // array.length == 3 OR you pressed #
{
lcd.clear();
pantallaprincipal();
editmodo = false; // disable edit mode
tipomodoCount = 0; // reset your counter
finalmodoValue = atoi(ttmodo); // save your entered value for further usage
}
}
}
void canal()
{
char key = mykeypad.getKey();
if(key) // check if any key was pressed
{
if(key =='B') // if * was pressed switch to edit mode
{
lcd.clear();
if (key >= '0' && key <= '9');
{
lcd.clear();
lcd.setCursor(0,0); // set your cursor at columnt 0, row 0
lcd.print("CANAL:");
editcanal = true;
lcd.setCursor(0,1); // set your cursor to second row
numerocanalCount = 0;
}
}
if(editcanal && numerocanalCount < 2 && key != 'B' && key != '#')
{
numerocanal[numerocanalCount] = key; // save key to a char array
lcd.setCursor(numerocanalCount,1); // set your cursor to the next position
lcd.print(numerocanal[numerocanalCount]); // print the pressed button to lcd
numerocanalCount++; // increment the array index (cursor position)
}
if( key == 'Z') // array.length == 3 OR you pressed #
{
lcd.clear();
pantallaprincipal();
editcanal = false; // disable edit mode
numerocanalCount = 0; // reset your counter
finalcanalValue = atoi(numerocanal); // save your entered value for further usage
}
}
}
void numtren()
{
char key = mykeypad.getKey();
if(key)
{
if(key == 'D') // if * was pressed switch to edit mode
{
if (key >= '0' && key <= '9');
{
lcd.clear();
lcd.setCursor(0,0); // set your cursor at columnt 0, row 0
lcd.print("NUMTREN:");
edit = true;
numerotrenCount = 0;
}
}
if(edit && numerotrenCount < 5 && key != 'D' && key != 'B' && key != '#')
{
numerotren[numerotrenCount] = key; // save key to a char array
lcd.setCursor(numerotrenCount,1); // set your cursor to the next position
lcd.print(numerotren[numerotrenCount]); // print the pressed button to lcd
numerotrenCount++; // increment the array index (cursor position)
}
if( key == 'Z') // array.length == 3 OR you pressed #
{
lcd.clear();
pantallaprincipal();
edit = false; // disable edit mode
numerotrenCount = 0; // reset your counter
finalValue = atoi(numerotren); // save your entered value for further usage
}
}
}