// Mega Shell Paster Development Copy
// 3/11/13
#include <Wire.h>
#include <LiquidCrystal.h>
// The below just makes it easier to setup the LCD display,
// it lists the pins and assignments and then calls the routine
// that communicates with the display. The #define statements
// could've been left out and the pins simply put in the () for
// the lcd routine call.
#define Rs_pin 12
#define En_pin 11
#define D4_pin 10
#define D5_pin 9
#define D6_pin 8
#define D7_pin 7
LiquidCrystal lcd(Rs_pin, En_pin, D4_pin, D5_pin, D6_pin, D7_pin);
#include <Keypad.h>
const byte ROWS = 3; //three rows
const byte COLS = 3; //three columns
// Below defines the keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};
byte rowPins[ROWS] = {6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3, 2, 1}; //connect to the column pinouts of the keypad
// Everything needed for the keypad has been given, below creates it.
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned int shell_size_selection = 9;
// This sets the intial shell size to 8", you can set it to whatever size
// you want it to start at.
unsigned int shell_profile_selection = 1;
// There are currently four shell profiles per shell selected, this sets
// the profile selection to start at the first one.
unsigned int shell_action_selection = 1;
unsigned int current_page = 1;
// This is a flag to tell the program which menu page to be on.
unsigned int page_1_start_menu_left_arrow_location = 1;
void setup() {
}
void loop() {
// This is the main running loop of the program
//
switch (current_page) {
case (1):
page_1_start_menu ();
break;
case (2):
page_2_shell_select ();
break;
case (3):
page_3_shell_profile_select ();
break;
case (4):
page_4_action_select ();
break;
default:
current_page = 1;
lcd.clear();
break;
}
}
//***** These are functions to be called by the main program *****
//
void page_1_start_menu () {
lcd.setCursor(0,0); // sets the cursor to column zero on row zero
lcd.print("Select Shell");
lcd.setCursor(0,1); // sets the cursor to column zero on row one
lcd.print("System Config");
byte left_arrow[8] = { // Create byte array with <-
B00010,
B00100,
B01000,
B11111,
B01000,
B00100,
B00010,
B00000};
lcd.createChar(0, left_arrow); // Create custom character 0
//
switch (page_1_start_menu_left_arrow_location) {
case (1):
lcd.setCursor(14,0);
break;
case (2):
lcd.setCursor(14,1);
break;
}
lcd.write((byte)0); // Write custom char 0
//
char key = keypad.getKey(); // check the keypad
if(key) // Check for a valid key.
switch (key) {
case ('2'):
page_1_start_menu_left_arrow_location = 1;
lcd.setCursor(14,1);
lcd.print(" ");
break;
case ('8'):
page_1_start_menu_left_arrow_location = 2;
lcd.setCursor(14,0);
lcd.print(" ");
break;
case ('5'):
lcd.clear();
if (page_1_start_menu_left_arrow_location==1) current_page = 2;
break;
}}
// End of page_1_start_menu function
//
void page_2_shell_select () {
lcd.setCursor(0,0);
lcd.print("Shell Size: ");
//
display_shell_size_selected ();
//
char key = keypad.getKey(); // check the keypad
switch (key) {
case ('4'): { // left arrow pressed
--shell_size_selection; // decrement shell size by one
if (shell_size_selection == 0) shell_size_selection=12; // if at min roll over to the max
break;
}
case ('6'): { // right arrow pressed
++shell_size_selection; // increment shell size by one
if (shell_size_selection == 13) shell_size_selection=1; //if at max size roll over to min
break;
}
case ('5'): { // select pressed
current_page = 3;
break;
{
case ('2'): { // up arrow pressed
current_page = 1;
lcd.clear();
break;
}
}}}}
// End of page_2_shell_select function
//
void display_shell_size_selected () {
// the below looks up the menu text to display for the shell size selections
lcd.setCursor(12,0); // sets the cursor to column 12 on row zero
switch (shell_size_selection) {
case (12):
lcd.print("16 ");
break;
case (11):
lcd.print("12 ");
break;
case (10):
lcd.print("10 ");
break;
case (9):
lcd.print("8 ");
break;
case (8):
lcd.print("6 ");
break;
case (7):
lcd.print("5 ");
break;
case (6):
lcd.print("4 ");
break;
case (5):
lcd.print("3 ");
break;
case (4):
lcd.print("2-1/2");
break;
case (3):
lcd.print("2 ");
break;
case (2):
lcd.print("1-3/4");
break;
case (1):
lcd.print("1-1/2");
break;
}
}
// End of display_shell_size_selected function
void page_3_shell_profile_select () {
lcd.setCursor(0,1);
lcd.print("Profile: ");
display_shell_profile_selected ();
char key = keypad.getKey(); // check the keypad
switch (key) {
case ('4'): { // left arrow pressed
--shell_profile_selection; // decrement shell profile by one
if (shell_profile_selection == 0) shell_profile_selection=4; // if at min roll over to the max
break;
}
case ('6'): { // right arrow pressed
++shell_profile_selection; // increment shell profile by one
if (shell_profile_selection == 5) shell_profile_selection=1; //if at max size roll over to min
break;
}
case ('5'): { // select pressed
current_page = 4;
break;
{
case ('2'): { // up arrow pressed
current_page = 2;
lcd.clear();
break;
}
}}}}
// end of page 3 function
//
void display_shell_profile_selected () {
// the below looks up the menu text to display for the shell profile selections
lcd.setCursor(9,1); // sets the cursor to column 12 on row one
switch (shell_profile_selection) {
case (1):
lcd.print("Gen Chinese");
break;
case (2):
lcd.print("Lidu ");
break;
case (3):
lcd.print("S & C ");
break;
case (4):
lcd.print("Blank ");
break;
}
}
// End of display_shell_profile_selected function
void page_4_action_select () {
lcd.setCursor(0,2);
lcd.print("Action: ");
display_shell_action_selected ();
char key = keypad.getKey(); // check the keypad
switch (key) {
case ('4'): { // left arrow pressed
--shell_action_selection; // decrement shell profile by one
if (shell_action_selection == 0) shell_action_selection=3; // if at min roll over to the max
break;
}
case ('6'): { // right arrow pressed
++shell_action_selection; // increment shell profile by one
if (shell_action_selection == 4) shell_profile_selection=1; //if at max size roll over to min
break;
}
case ('5'): { // select pressed
current_page = 4;
break;
{
case ('2'): { // up arrow pressed
current_page = 3;
lcd.clear();
break;
}
}}}}
void display_shell_action_selected () {
// the below looks up the menu text to display for the shell action selections
lcd.setCursor(8,2); // sets the cursor to column 8 on row two
switch (shell_action_selection) {
case (1):
lcd.print("Paste Shell ");
break;
case (2):
lcd.print("Burnish ");
break;
case (3):
lcd.print("Edit Profile");
break;
}
}
// End of display_shell_profile_selected function