Skip to content


Adding Menu

I did not change the HW since the last post. I updated the SW by implementing a simple menu:

// include the library code:
 #include <LiquidCrystal.h>

 const int numRows = 2;
 const int numCols = 16;

 const int lcdBackLightPin = 12;
 const int upButtonPin = 6;
 const int downButtonPin = 5;
 const int setButtonPin = 4;
 const int resetButtonPin = 3;

 char* mainMenu[]={"start", "delay", "test"};
 int mainMenuIndex = 0;
 int mainMenuNextItem = 1;
 int mainMenuItemNum = 3;
 boolean menuUpdate = false;

 // initialize the library with the numbers of the interface pins
 LiquidCrystal lcd(13, 11, 10, 9, 8, 7);

 void setup() {
 // set up the LCD's number of rows and columns:
 lcd.begin(numRows, numCols);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print(">");
 lcd.setCursor(2, 0);
 lcd.print(mainMenu[mainMenuIndex]);
 lcd.setCursor(2, 1);
 lcd.print(mainMenu[mainMenuNextItem]);
 digitalWrite(lcdBackLightPin, HIGH);

 pinMode(lcdBackLightPin, OUTPUT);
 pinMode(upButtonPin, INPUT);
 pinMode(downButtonPin, INPUT);
 pinMode(setButtonPin, INPUT);
 pinMode(resetButtonPin, INPUT);

 }

 void loop() {
 if(digitalRead(upButtonPin))
 {
 mainMenuIndex++;
 if(mainMenuIndex >= mainMenuItemNum)
 {
 mainMenuIndex = 0;
 }  
 mainMenuNextItem++;
 if(mainMenuNextItem >= mainMenuItemNum)
 {
 mainMenuNextItem = 0;
 }
 menuUpdate = true;
 }
 else if(digitalRead(downButtonPin))
 {
 mainMenuIndex--;
 if(mainMenuIndex < 0)
 {
 mainMenuIndex = mainMenuItemNum - 1;
 }  
 mainMenuNextItem--;
 if(mainMenuNextItem < 0)
 {
 mainMenuNextItem = mainMenuItemNum - 1;
 }
 menuUpdate = true;
 }

 if(menuUpdate)
 {   
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print(">");
 lcd.setCursor(2, 0);
 lcd.print(mainMenu[mainMenuIndex]);
 lcd.print(" <");
 lcd.setCursor(2, 1);
 lcd.print(mainMenu[mainMenuNextItem]);
 menuUpdate = false;
 delay(300);
 }

 }

You can download the file from here: xISTIxHSPC

Posted in microcontroller, xISTIx HSP Controller.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

You must be logged in to post a comment.