Hi there -
I am trying to run a simple program which involves a keypad and LCD screen and need help structuring the code. The LCD will prompt the user to enter info into the keypad, saves the info, then prompts again for another key strike which then runs a math equation with the info until the user presses the keypad again to finish.
Any help would be greatly appreciated!!!!! Thanks. Here is the code I have so far.
#include <SoftwareSerial.h>
#include <Keypad.h>
char N;
int I;
int ByteVar;
int NN;
int Remainder;
int Num_5;
#define rxPin 11 // rxPin is immaterial - not used - just make this an unused Arduino pin number
#define txPin 14 // pin 14 is analog pin 0, on a BBB just use a servo cable :), see Reference pinMode
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// mySerial is connected to the TX pin so mySerial.print commands are used
// one could just as well use the software mySerial library to communicate on another pin
void setup(){
keypad.addEventListener(keypadEvent); //add an event listener
pinMode(txPin, OUTPUT);
mySerial.begin(9600); // 9600 baud is chip comm speed
mySerial.print("?G216"); // set display geometry, 2 x 16 characters in this case
delay(500); // pause to allow LCD EEPROM to program
mySerial.print("?Bff"); // set backlight to ff hex, maximum brightness
delay(1000); // pause to allow LCD EEPROM to program
mySerial.print("?s6"); // set tabs to six spaces
delay(1000); // pause to allow LCD EEPROM to program
mySerial.print("?D00000000000000000"); // define special characters
delay(300); // delay to allow write to EEPROM
// see moderndevice.com for a handy custom char generator (software app)
mySerial.print("?f"); // clear the LCD
delay(10);
}
void loop()
{
mySerial.print("Welcome to the Opportunity Cost Calculator");
delay(4000);
mySerial.print("?f");
mySerial.print("Press 1 to Begin");
//This is where I need it to delay until the user presses 1
{
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey) {
switch (eKey) {
case '1':
mySerial.print("hello");
break;
//not sure what to do now or how to structure it to go to another prompt.
case KEY_RELEASED:
Serial.println("Key Released");
break;
default:
if (eKey) { // same as if(eKey != NO_KEY)
Serial.println(eKey);
}
}
}