From power up the LCD shows Time and Date
I can navigate the menu but seem to be always stuck in case 1: or case 2: I cant seem to change the Rtc parameters as I just get put back into the menu.
void loop()
{
if (menuRoot == true)
{
lcd.setCursor(4, 0);
lcd.print(rtc.formatTime());
lcd.setCursor(3, 1);
lcd.print(rtc.formatDate());
I then navigate the menus using the encoder
void readEncoder() //read the encoder and set lastButtonPushed to values used by navigateMenu()
{
n = digitalRead(encoder0PinA);// n is current state of encoder0PinA pin
if ((encoder0PinALast == HIGH) && (n == LOW)) // check if encoder0PinA pin has changed state
{
if (digitalRead(encoder0PinB) == LOW)
{
lastButtonPushed = 1; //if it has changed and its now low decrement encoder0Pos;
}
else
{
lastButtonPushed = 2; // if it has changed and its now high, increment encoder0Pos
}
}
encoder0PinALast = n; // set the variable holding the previous state to the value n read above
}
Then using case 1; or case 2 of the void navigateMenus, I move Left/Right through the menu till I get to for example "Min" from void menuChanged.
void menuChanged(MenuChangeEvent changed){
MenuItem newMenuItem=changed.to; //get the destination menu
lcd.setCursor(0,0); //set the start position for lcd printing to the second row
if(newMenuItem.getName()==menu.getRoot()){
lcd.clear();
menuRoot = true;
}
//MENU SET CLOCK
else if(newMenuItem.getName()=="menuSetClock"){
menuRoot = false;
lcd.clear();
lcd.print("Set Clock");
}
else if(newMenuItem.getName()=="menuItemHr"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Hr");
}
else if(newMenuItem.getName()=="menuItemMin"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Min");
}
}
Now that I have "Min" displayed on the LCD. I select it by pressing the encoder push button on pin 45.
void menuUsed(MenuUseEvent used){ // **if you have a function call it here**
if ( used.item == menuItemHr ){
lcd.clear();//etc.
lcd.setCursor(0, 0);
lcd.print(rtc.formatTime());
changeHour();
}
else if ( used.item == menuItemMin ){
lcd.clear();//etc.
lcd.setCursor(0, 0);
lcd.print(rtc.formatTime());
changeMin();
}
if ( used.item == menuExit ){
menu.toRoot();//etc.
}
}
This now shows the LCD displaying the clock. because of the function changeMin() called from void menuUsed above
void changeMin(){
{
min = ++min % 60; // this is better than // min += 1;as it rolls overfrom 59 to 00
//if (incrementMinuteButtonPressDectected) min = ++min % 60 // increment and rollover past 59
//if (decrementMinuteButtonPressDectected) min = (--min + 60) % 60 // decrement and rollunder past 0
}
rtc.setTime(hour, min,sec);
}
At this point If I use the encoder case 1 or case 2, it does not change the Mins on the clock. It simply navigates the menu left or right.
but if I press the encoder push button, the minutes change... hope this helps. I have included attachment of the Full code below.
doc.txt (16.9 KB)