Created
September 11, 2012 10:58
-
-
Save jeena/3697594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <MenuBackend.h> | |
#include <LiquidCrystal.h> | |
#define VERSION "0.0.1" | |
#define B_UP 0 | |
#define B_DOWN 1 | |
#define B_ENTER 2 | |
#define B_CANCEL 3 | |
#define LCD_ROWS 20 | |
#define LCD_LINES 4 | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
const int buttonPins[] = {6, 7, 9, 10}; | |
int buttonStates[] = {LOW, LOW, LOW, LOW}; | |
long lastDebounceTimes[] = {0, 0, 0, 0}; | |
long debaunceDelay = 500; | |
const int ledPin = 13; | |
void setup() { | |
for(int i = 0; i < 4; i++) { | |
pinMode(buttonPins[i], INPUT); | |
} | |
lcd.begin(LCD_ROWS, LCD_LINES); | |
lcd.clear(); | |
lcd.setCursor(3, 1); // Center the text | |
lcd.print("Jrims v " VERSION); | |
delay(2000); | |
menuSetup(); | |
} | |
void loop() { | |
navigateMenu(); | |
} | |
MenuBackend menu = MenuBackend(menuUseEvent, menuChangeEvent); | |
MenuItem runProgram("Run program"); | |
MenuItem changeProgram("Change program"); | |
MenuItem changeMashing("Mashing"); | |
MenuItem changeSparging("Sparging"); | |
MenuItem changeBoiling("Boiling"); | |
MenuItem changeChilling("Chilling"); | |
void menuSetup() { | |
menu.getRoot().add(runProgram); | |
runProgram.addAfter(changeProgram); | |
changeProgram.addAfter(runProgram); | |
changeProgram.addLeft(changeProgram); | |
changeProgram.addRight(changeMashing); | |
changeMashing.addAfter(changeSparging); | |
changeMashing.addBefore(changeChilling); | |
changeMashing.addLeft(changeProgram); | |
changeSparging.addAfter(changeBoiling); | |
changeSparging.addBefore(changeMashing); | |
changeSparging.addLeft(changeProgram); | |
changeBoiling.addAfter(changeChilling); | |
changeBoiling.addBefore(changeSparging); | |
changeBoiling.addLeft(changeProgram); | |
changeChilling.addAfter(changeMashing); | |
changeChilling.addBefore(changeBoiling); | |
changeChilling.addLeft(changeProgram); | |
printMenuItem(&runProgram); | |
} | |
void menuUseEvent(MenuUseEvent used) { | |
lcd.clear(); | |
lcd.print("Used: "); | |
lcd.println(used.item.getName()); | |
} | |
void menuChangeEvent(MenuChangeEvent changed) { | |
MenuItem itemCurrent = changed.to; | |
lcd.clear(); | |
lcd.print(itemCurrent.getName()); | |
} | |
void printMenuItem(const MenuItem *itemCurrent) { | |
MenuItem *itemAfter = itemCurrent->getAfter(); | |
int line = 0; | |
lcd.clear(); | |
lcd.print("> "); | |
lcd.print(itemCurrent->getName()); | |
while(itemAfter && itemAfter != itemCurrent) { | |
lcd.setCursor(2, ++line); | |
lcd.print(itemAfter->getName()); | |
itemAfter = itemAfter->getAfter(); | |
} | |
} | |
void navigateMenu() { | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment