I have an LCD Keypad shield (16x2 with up,down,left,right,select buttons) and I want to prompt the user to enter a weight in kgs. The number will be greater than 10 thousand kgs. In my code below I use the up and down buttons to either add 1 or subtract 1 from the current value for that cursor space. The right button moves onto the next cursor space and the left one moves back a cursor space.
The problem is that the number displayed, ex: 12500, is not twelve thousand five hundred but yet one-two-five-zero-zero. It is not 1 number but yet a series of 5 numbers printed on the screen. It is important to store the number as it will be used later in the program.
Is it possible to enter and store a number like this? Or will I have to make multiple functions prompting the user to enter ten-thousands, thousands, hundreds etc., and then multiply the variable by its multiplier (x10 000, x1000, x*100) and add them all up?
ALSO:
- The buttons are kind of “jumpy” when I press them. Is there a way to counteract this? Maybe by setting up delays?
- How do I make the values only be a positive number? Where do I insert an abs function?
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int ans = 0;
int a = 0; //used for moving the cursor left or right.
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Enter kgs:");
}
void loop() {
int x;
x = analogRead (0);
lcd.setCursor(a,1);
if (x < 60) {
//right button
a++;
ans = 0;
}
else if (x < 200) {
//up button
ans++;
lcd.print(ans);
}
else if (x < 400){
//down button
ans--;
lcd.print(ans);
}
else if (x < 600){
//left button
a--;
}
else if (x < 800){
//want to use this to save the value and move onto another function.
}
delay(100);
}