I tried adding a function and I couldn't give it user input properly, I could only back out of the menu... Here is my entire code at the moment:
#include <Keypad.h>
#include <glcd.h>
#include <glcd_Buildinfo.h>
#include <glcd_Config.h>
#include "fonts/allFonts.h"
int ledPin = 13;
boolean menuActive = false; //
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] = {
40, 41, 42, 43}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
44, 45, 46}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
pinMode(ledPin, OUTPUT);
GLCD.Init();
GLCD.SelectFont(System5x7);
GLCD.println("VOSHA UCP");
GLCD.println("Press * for menu");
GLCD.println("1. Lamp toggle");
GLCD.println("2. Alarm silence");
GLCD.println("3. Alarm sound");
GLCD.println("4. LED value set");
}
void loop() {
char key = keypad.getKey();
switch (key) {
case '*':
menuActive = true;
GLCD.ClearArea();
GLCD.println("1. LED On");
GLCD.println("2. LED Off");
GLCD.println("3. LED Blink");
GLCD.println("4. Master Config");
GLCD.println("5. MenuItem5");
GLCD.println("6. MenuItem6");
GLCD.println("7. MenuItem7");
GLCD.println("# To exit menu");
break;
case '#':
menuActive = false;
HomeScreen();
break;
case '1':
if (menuActive == true) {
digitalWrite(ledPin, HIGH);
ActionCompleted();
}
break;
case '2':
if (menuActive == true) {
digitalWrite(ledPin, LOW);
ActionCompleted();
}
break;
case '3':
if (menuActive == true) {
ActionCompleted();
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
}
break;
case '4':
if (menuActive == true) {
MasterConfig();
break;
default:
break;
}
}
}
void HomeScreen() { //Routine to display home screen and provide updates
GLCD.ClearArea();
GLCD.println("VOSHA UCP");
GLCD.println("Press * for menu");
GLCD.println("1. Lamp toggle");
GLCD.println("2. Alarm silence");
GLCD.println("3. Alarm sound");
GLCD.println("4. LED value set");
}
void ActionCompleted() {
GLCD.ClearArea();
GLCD.CursorTo(0,0);
GLCD.print("Action completed!");
delay(500);
menuActive = false;
HomeScreen();
}
void MasterConfig() {
menuActive = false;
GLCD.ClearArea();
GLCD.println("Master Configuration");
GLCD.println("# To exit menu");
GLCD.println("1. Device ID");
char key2 = keypad.getKey();
switch (key2) {
case '1':
GLCD.ClearArea();
GLCD.println("Device ID menu");
break;
default:
break;
}
}
MasterConfig is where I have moved that menu to try out Hazards suggestion and I can't give it input...
uber