#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int buzzerPin = 10;
const int ledPin = 13;
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] = {28, 29, 30, 31};
byte colPins[COLS] = {24, 25, 26, 27};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String monto = "";
bool esperaTarjeta = false;
void setup() {
lcd.init();
lcd.backlight();
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
lcd.setCursor(0, 0);
lcd.print("Ingrese el Monto:");
}
void loop() {
char key = keypad.getKey();
if (key && ((key >= '0' && key <= '9') || key == '.')) {
if (monto.length() < 16) {
monto += key;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ingrese el Monto:");
lcd.setCursor(0, 1);
lcd.print(monto);
tone(buzzerPin, 2000);
digitalWrite(ledPin, HIGH);
delay(100);
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
}
} else if (key == 'A') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Monto a debitar:");
lcd.setCursor(0, 1);
lcd.print(monto);
esperaTarjeta = true;
digitalWrite(ledPin, HIGH); // Encender LED y mantenerlo encendido
} else if (key == 'B') {
if (monto.length() > 0) {
monto.remove(monto.length() - 1);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ingrese el Monto:");
lcd.setCursor(0, 1);
lcd.print(monto);
}
} else if (key == 'C' && esperaTarjeta) {
reiniciarSistema();
}
// Aquí podrías agregar la lógica para detectar la tarjeta.
// if (detectarTarjeta()) {
// realizarTransaccion();
// esperaTarjeta = false;
// digitalWrite(ledPin, LOW); // Apagar LED después de la transacción
// }
}
void reiniciarSistema() {
monto = "";
esperaTarjeta = false;
digitalWrite(ledPin, LOW); // Apagar LED
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ingrese el Monto:");
}