#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <AceSorting.h>
using ace_sorting::bubbleSort;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 7, 6, 5, 4 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 13, 12, 11, 10 }; // Pins connected to R1, R2, R3, R4
int cursor = 0;
int numbers[] = {};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.blink();
lcd.setCursor(0,0);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY && cursor < 16) {
lcd.print(key);
if (key == 'A') {
// sort algorithm
Serial.print(numbers[0]);
bubbleSort(numbers, sizeof(numbers));
Serial.println("\n");
cursor = 0;
lcd.clear();
// update screen
while (cursor < 16) {
lcd.print (numbers[cursor]);
cursor += 1;
}
}
// Serial.println(key);
numbers[cursor] = atoi(key);
cursor += 1;
lcd.setCursor(cursor,0);
}
}