101 lines
2.4 KiB
C++
101 lines
2.4 KiB
C++
/*4x4 Matrix Keypad connected to Arduino
|
||
This code prints the key pressed on the keypad to the serial port*/
|
||
//LIBRERIAS
|
||
#include <Wire.h>
|
||
#include <Keypad.h>
|
||
#include <LiquidCrystal.h>
|
||
//------------
|
||
//MATRIZ
|
||
const byte numRows= 3; //number of rows on the keypad
|
||
const byte numCols= 11; //number of columns on the keypad
|
||
//keymap defines the key pressed according to the row and columns just as appears on the keypad
|
||
char keymap[numRows][numCols]=
|
||
{
|
||
{'z','b','c','v','b',' ','n','m','.','?','ç'},
|
||
{'q','w','e','r','t','y','u','i','p','`','o'},
|
||
{'a','s','d','f','g','h','j','k','ñ','´','l'}
|
||
};
|
||
//Code that shows the the keypad connections to the arduino terminals
|
||
byte rowPins[numRows] = {31,33,35}; //Rows 0 to 3 13 12 11
|
||
byte colPins[numCols]= {37,39,41,43,45,47,49,51,53,52,50}; //Columns 0 to 3 10 9 8 7 6 5 4 3 2 14 15
|
||
//-------------
|
||
//initializes an instance of the Keypad class
|
||
char texto[7];
|
||
int v1;
|
||
int v2;
|
||
int x=0;
|
||
byte a = 0;
|
||
int value=0;
|
||
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
|
||
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
|
||
|
||
void setup()
|
||
{
|
||
|
||
lcd.begin(16, 2); // start the library
|
||
lcd.setCursor(0,0);
|
||
//ENVIADO
|
||
pinMode(22,OUTPUT);
|
||
pinMode(24,INPUT);
|
||
digitalWrite(22, HIGH);
|
||
Wire.begin();
|
||
//-------
|
||
Serial.begin(9600);
|
||
v1 = 0;
|
||
v2 = 0;
|
||
}
|
||
|
||
byte env = 0;
|
||
|
||
//If key is pressed, this key is stored in 'keypressed' variable
|
||
//If key is not equal to 'NO_KEY', then this key is printed out
|
||
//if count=17, then count is reset back to 0 (this means no key is pressed during the whole keypad scan process
|
||
|
||
void loop(){
|
||
|
||
value=digitalRead(24);
|
||
char keypressed = myKeypad.getKey();
|
||
v1 = 0;
|
||
if (x != 7){
|
||
if (keypressed != NO_KEY){
|
||
v1 = 1;
|
||
if(v1 == 1 && v2 == 0){
|
||
texto [x] =keypressed;
|
||
lcd.print(keypressed);
|
||
Serial.print(keypressed);
|
||
//Serial.print(texto[x]);
|
||
x++;
|
||
}
|
||
}
|
||
}
|
||
v2 = v1;
|
||
delay(100);
|
||
if(keypressed == '?'){
|
||
lcd.clear();
|
||
lcd.print("ENVIANDO...");
|
||
//----ENVIO----
|
||
|
||
enviar();
|
||
|
||
delay(5000);
|
||
x = 0;
|
||
lcd.clear();
|
||
//-------------
|
||
}
|
||
}
|
||
|
||
void enviar()
|
||
{
|
||
|
||
int Nletras= x;
|
||
int indexLetras=0;
|
||
for(int Nmariposas=0; Nmariposas<Nletras; Nmariposas=Nmariposas+1)
|
||
{
|
||
Wire.beginTransmission(Nmariposas); // transmit to device #x+1
|
||
Wire.write(texto[Nmariposas]);
|
||
Wire.endTransmission(); // stop transmitting
|
||
}
|
||
}
|
||
|
||
|