I used this note to test my keypad and I need at least 6 points to float correctly. After working at least 7 digits it goes wrong. Please tell me how to fix it. I must enter 9 digits at a time and the return floating value must be correct to at least 6 digits on return. (Ex: Input => 123456789 and Exit => 123.456789)
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'C', '0', '=', '/'}
};
byte rowPins[ROWS] = {11, 10, 9, 8};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
}
void loop() {
long va = function();
Serial.print("Value is ");
Serial.print(va);
Serial.print(" Value 2 is ");
double lati = double(va) / 1000000;
Serial.println(lati,6);
delay(2000);
}
long function()
{
Serial.println("enter Value ");
long valu = 0;
long key = 0;
int index;
do {
key = customKeypad.getKey();
index = (key >= '0' && key <= '9');
if (index)
{
Serial.print(key - '0');
valu = (valu * 10 + key - '0');
}
}
while (index || !key);
Serial.println();
return valu;
}
My outputs...
enter Value
123456
Value is 123456 Value 2 is 0.123456
enter Value
1234567
Value is 1234567 Value 2 is 1.234567
enter Value
12345678
Value is **12345678 Value 2 is 12.345679**
enter Value
14785236
Value is **14785236 Value 2 is 14.785237**
enter Value