Hi, so I'm new to coding and was wondering if I could get some help. This is what I would like my code to do:
- display numbers input from keypad.
- when '#' is pressed, send the number/numbers entered into a function.
- return a result from the function.
- display the result.
I had it clear and start over if the number of digits entered went over 7, but after changing the code, it doesn't do that anymore. I tried working backwards, but I couldn't fix it. Also I'm not sure how send the entered numbers to the function.
I feel like there is a lot that I'm doing wrong with the code.
I would appreciate it if I could get some help with this!
Thank you!
Here is what I have so far.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'*', '0', '#', 'D'},
{'7', '8', '9', 'C'},
{'4', '5', '6', 'B'},
{'1', '2', '3', 'A'},
};
byte rowPins[ROWS] = {4, 3, 2, 1}; //connect to the row pinouts of the keypad (+3) for nano
byte colPins[COLS] = {5, 6, 7, 8}; //connect to the column pinouts of the keypad (+3) for nano
int number;
int count = 0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_I2C lcd(0x27, 16, 2);
int key = keypad.getKey();
void setup()
{
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Enter Number!");
lcd.setCursor(0, 1);
lcd.print("Number= ");
}
void loop()
{
static char userinput [7];
static int count = 0;
float add;
char key = keypad.getKey();
if (key != NO_KEY)
{
lcd.print(key);
count++;
if (count >= 7)
{
lcd.clear();
lcd.print("Enter Number!");
lcd.setCursor(0, 1);
lcd.print("Number= ");
count = 0;
}
if (key == '*')
{
lcd.clear();
lcd.print("Enter Number!");
lcd.setCursor(0, 1);
lcd.print("Number= ");
count = 0;
}
if (key == 'A')
{
lcd.clear();
lcd.print("Enter Number!");
lcd.setCursor(0, 1);
lcd.print("Number= ");
count = 0;
}
if (key == 'B')
{
lcd.clear();
lcd.print("Enter Number!");
lcd.setCursor(0, 1);
lcd.print("Number= ");
count = 0;
}
if (key == 'C')
{
lcd.clear();
lcd.print("Enter Number!");
lcd.setCursor(0, 1);
lcd.print("Number= ");
count = 0;
}
if (key == 'D')
{
lcd.clear();
lcd.print("Enter Number!");
lcd.setCursor(0, 1);
lcd.print("Number= ");
count = 0;
}
if (count < 7)
{
userinput [count++] = key;
}
if (key == '#')
{
memset (userinput, 0, sizeof(userinput));
lcd. print(add);
}
}
}
float calc(int, int key)
{
float result;
result = 31 + key;
return result;
}
input.ino (2.14 KB)