17.- Write number with KeyPad in Arduino and sends to App by Bluetooth. LCD I2C.
p9A0i_bluetooth_teclado.aia (1.8 MB)
- Write number with KeyPad + I2C: 123, 4567, 89, 61 then write # (as ENTER)
- That number is displayed on the I2C LCD and is sent via Bluetooth.
- Depending on the number sent, the image of a monkey, lion, bear or martians will be displayed in App.
// Juan A. Villalpando
// http://kio4.com/appinventor/9BA_bluetooth_teclado_LCD.htm
#include <Wire.h>
#include <Keypad_I2C.h>
// Pantalla LCD
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
String clave = "";
String clave_old = "";
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {0, 1, 2, 3};
byte colPins[COLS] = {4, 5, 6, 7};
int i2caddress = 0x20; // Module I2C Keyboard.
Keypad_I2C kpd = Keypad_I2C( makeKeymap(keys), rowPins, colPins, ROWS, COLS, i2caddress);
void setup() {
Serial.begin(9600);
kpd.begin();
lcd.begin(16,2);// Columnas y filas de LCD.
}
void loop() {
char key = kpd.getKey();
clave = clave + (String) key;
if (key == '#') {
clave = clave.substring(0, clave.length() - 1); // Delete last char #
lcd.clear();
lcd.setCursor(0,0);
lcd.print(clave);
lcd.setCursor(0,1);
lcd.print(clave_old);
clave_old = clave;
Serial.println(clave);
clave = "";
}
delay(100);
}