I started this on another thread, but the thread started to skew too far from what the original post was about, so now I'm beginning a new, more relevant one.
I'm using an Arduino Mega Mini, a 4x4 Matrix Keypad, and a 16x2 LCD screen.
What I'd like to do is type in a set of numbers with the keypad, and turn them into a 'float' variable (which will be named 'num1'). The numbers will then be printed onto a 16x2 LCD screen
The first set of numbers will look something like this:
2.5546
The numbers I type will vary, but the amount of decimal places will stay the same.
Right now all I really know how to do is get the numbers to print onto the LCD screen. /:
I've tried a ton of things involving strings and arrays, but I always end up having to rebuild the code from scratch afterwards, when it goes awry.
Here it is in it's most basic form:
#include "Adafruit_LiquidCrystal.h"
#include "Keypad.h"
const byte ROWS = 4;
const byte COLS = 4;
float num1 = 0;
float num2 = 0;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'.', '0', ',', 'D'}
};
byte rowPins[ROWS] = {25, 27, 29, 31};
byte colPins[COLS] = {17, 19, 21, 23};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
unsigned int deBounce = 100;
Adafruit_LiquidCrystal lcd (8, 9, 3, 10, 11, 12, 13);
void setup() {
customKeypad.setDebounceTime(deBounce);
lcd.begin(16, 2); // Setup the LCD
lcd.setCursor(0, 0);
lcd.print(F("Version 8.6-Frm"));
delay(5000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print(F("Res. Peak Calc."));
lcd.setCursor(0, 1);
lcd.print(F("Type I/C values"));
delay(5000);
lcd.clear();
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey) {
switch (customKey) {
case '0' ... '9':
lcd.print(customKey);
break;
case '.':
lcd.print(customKey);
break;
case ',':
lcd.print(customKey);
break;
case 'A':
lcd.print(customKey);
break;
case 'B':
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Ind. = "));
lcd.print(num1);
lcd.setCursor(0, 1);
lcd.print(num2);
delay(2500);
lcd.clear();
break;
case 'C':
lcd.clear();
num1 = 0;
break;
case 'D':
lcd.print(customKey);
break;
}
}
}
I want to type in my numbers and decimal, and then make all of them be the value for 'num1'.
Other users have mentioned that I have to type a number, turn it into an integer, type another number, turn it into another integer, and then turn those two digits into their own digit, etc.
I have no clue how to do this^^. That's where I'm needing some guidance, or some advice on another method.
Any suggestions on how I might do this, or does anybody know of a pre-existing code or example that does this already?
Thanks for any help! And to those who have helped, if you're reading this - thanks again!
You're awesome