#include <LiquidCrystal.h>
#include <Keypad.h>
#include <stdlib.h>
#include <stdio.h>
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] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String v_passcode="";
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
double *data;
void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Enter number");
lcd.setCursor(0,1);
lcd.print("of elements.");
}
void loop() {
int n;
n = keypad.getKey(); //Storing Elements
data = (double *)calloc(n, sizeof(double));
if (n != NO_KEY){
if (n == '0'){
lcd.clear();
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Error! Memory");
lcd.setCursor(0,1);
lcd.print("not allocated.");
}
}
if (n == 'D'){
getnumber(n);
}
free(data);
}
void getnumber(int n){
data = keypad.getKey();
lcd.clear();
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Enter Numbers.");
if (data == 'D'){
//To compute the largest number
for (int i = 1; i < n; ++i) {
if (*data < *(data + i)) {
*data = *(data + i);
}
}
lcd.clear();
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Largest Number:");
lcd.setCursor(0,1);
lcd.print(*data);
}
}