I am a beginner with Arduino
I make a code that save variable from keypad
The number I entered with the following code neither displayed on LCD nor saved to Arduino
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] =
{{'1','2','3','.'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
byte rowPins[ROWS] = {14, 15, 16, 17}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {18, 19, 20, 21}; //connect to the column pinouts of the keypad
int count=0;
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
byte index = 0;
char numbers[20]; // Plenty to store a representation of a float
float myvar;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(18, 4);
lcd.clear();
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("myvar: ");
lcd.setCursor(0,2);
lolo5 = GetNumber();
}
int GetNumber()
{
char key = kpd.getKey();
if(key != NO_KEY)
{
if(key == 'A')
{
index = 0;
numbers[index] = '\0';
}
else if(key == '*')
{
numbers[index++] = '.';
numbers[index] = '\0';
}
else if(key >= '0' && key <= '9')
{
numbers[index++] = key;
numbers[index] = '\0';
}
else if(key == 'B')
{
float myvar = atof(numbers); // Do whatever you need to with len
index = 0;
numbers[index] = '\0';
}
}
}