// TEAM 2 - ACTIVITY 3 - PROCEDURE
// Finding the Largest Number
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const byte ROWS = 4;
const byte COLUMNS = 4;
byte rPins[ROWS] = {5, 4, 3, 2};
byte cPins[COLUMNS] = {A3, A2, A1, A0};
char keys[ROWS][COLUMNS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'.', '0', '=', '/'}
};
Keypad keypad = Keypad(makeKeymap(keys), rPins, cPins, ROWS, COLUMNS);
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
}
void loop() {
double *data;
lcd.print("NO. OF ELEMENTS:");
lcd.setCursor(0, 1);
char key = NULL;
String elements = "";
String inputElements = "";
int n;
while (key != '=') {
key = keypad.getKey();
if (key >= '0' && key <= '9')
{
lcd.print(key);
elements += key;
}
}
n = elements.toDouble();
delay(1000);
lcd.clear();
data = (double *)calloc(n, sizeof(double));
for (int i = 0; i < n; ++i) {
lcd.setCursor(0, 0);
lcd.print("COMPARE ELEMENTS(" + String(n) + "):");
lcd.setCursor(0, 1);
key = NULL;
while (key != '=') {
key = keypad.getKey();
if (key >= '0' && key <= '9' || key == '.') {
inputElements += key;
lcd.print(key);
}
}
data[i] = inputElements.toDouble();
inputElements = "";
lcd.clear();
}
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("LARGEST NUMBER:");
lcd.setCursor(0, 1);
for (int i = 1; i < n; ++i) {
if (*data < *(data + i)) {
*data = *(data + i);
}
}
lcd.print(*data);
while (true) {
continue;
}
}