So, I'm making a sort of dessert machine (don't mind me censoring what's written on the lcd) and am using a keypad to make the choices, however, I only use the numbers 1, 2, and 3 (first row and all first three columns). I applied changes to the code and downloaded it on the Arduino UNO. I opened the serial monitor and did the necessary to arrive at the phase which necessities input from the keypad. It was written "49" on the serial monitor, but I didn't even touch the keypad.
Here is the code:
#include <SPI.h>
#include <MFRC522.h>
#include <Keypad.h>
#include <Wire.h>
#include <NewPing.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
NewPing sonar(A0, A1, 21);
// Constants for row and column sizes
const byte ROWS = 1;
const byte COLS = 3;
// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'}
};
// Connections to Arduino
byte rowPins[ROWS] = {6};
byte colPins[COLS] = {5, 4, 3};
// Create keypad object
Keypad keypad1 = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
pinMode(3, OUTPUT);
lcd.init();
lcd.backlight();
lcd.clear();
}
bool dessertSel = false;
void loop() {
lcd.setCursor(1, 0);
lcd.print("Bla bla bla");
lcd.setCursor(2, 1);
lcd.print("bla bla bla bla");
lcd.setCursor(2, 2);
lcd.print("bla and bla");
while (! mfrc522.PICC_IsNewCardPresent()) {
return;
}
dessertSel = true;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("bla bla bla");
lcd.setCursor(0, 1);
lcd.print("bla bla bla bla bla");
lcd.setCursor(0, 2);
lcd.print("bla bla bla bla");
while (dessertSel == true) {
int customKey = keypad1.getKey();
if (customKey) {
Serial.print(customKey);
}
}
}
``
Can i get an explanation for why is this happening?
Thanks!