Skip to content

Instantly share code, notes, and snippets.

@robertcasanova
Created November 22, 2012 12:05
Show Gist options
  • Select an option

  • Save robertcasanova/4130816 to your computer and use it in GitHub Desktop.

Select an option

Save robertcasanova/4130816 to your computer and use it in GitHub Desktop.
LCD Menu
#include <LiquidCrystal.h> //this library is included in the Arduino IDE
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const int BTN_LEFT = 9;
const int BTN_RIGHT = 8;
const int BTN_CONFIRM = 10;
long last_read = 0;
char* list[] = {"menu1","menu2","menu3","menu4"};
byte index = 0;
void setup() {
pinMode(BTN_LEFT,INPUT);
pinMode(BTN_RIGHT,INPUT);
pinMode(BTN_CONFIRM,INPUT);
lcd.begin(16,2);
Serial.begin(9600);
printMenu(list[index]);
}
void loop() {
if(millis() - last_read > 200) {
if(digitalRead(BTN_LEFT) == 1) {
buttonClicked(BTN_LEFT);
}
if(digitalRead(BTN_RIGHT) == 1) {
buttonClicked(BTN_RIGHT);
}
if(digitalRead(BTN_CONFIRM) == 1) {
buttonClicked(BTN_CONFIRM);
}
last_read = millis();
}
}
void buttonClicked(int btn) {
if(btn == BTN_LEFT && index > 0 ) {
--index;
} else if (btn == BTN_RIGHT && index < 3) {
index++;
} else if (btn == BTN_CONFIRM) {
char cmd[500] = "{\"menuSelected\": \"";
strcat(cmd,list[index]);
strcat(cmd, "\"}");
Serial.println(cmd);
}
printMenu(list[index]);
}
void printMenu(String s) {
lcd.clear();
lcd.print("OpenRad.io");
lcd.setCursor(0,1);
lcd.print(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment