Menu for beer brewery

I would like to do a menu system, using a LCD-shield with five buttons (RGB LCD-shield, 16x2). The select-button should show different messages if I have pressed one, two or three times. My problem is that the first message shows for every press, but the second and third message is shown afterwards. Can someone help me to get rid of the first message?

Thanks in advance!

/*********************

Example code for the Adafruit RGB Character LCD Shield and Library

This code displays text on the shield, and also reads the buttons on the keypad.
When a button is pressed, the backlight changes color.

**********************/

// include the library code:
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>


// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

unsigned long time, desiredTemp, desiredTime, n;
byte numbr[4]; //hold 4 bytes 
  byte indx;    // will hold an index to the array
  int enteredTemp; //holds the final value entered
  int enteredTime; //holds the final value entered

  //to give the buttons more functions
byte buttonPresses = 0;                // how many times the button has been pressed
byte lastPressCount = 0;               // to keep track of last press count

void setup() {
 
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);

//meddelande vid start
  lcd.print("Temp = up/down");
  lcd.setCursor(0, 1);
  lcd.print("Time = left/right");

  desiredTemp=62;
  desiredTime=60;
  lcd.setBacklight(BLUE); //choose colour
}

uint8_t i=0;
void loop() {

//give functions to the buttons
  uint8_t buttons = lcd.readButtons();

  if (buttons) {
    lcd.clear();
    lcd.setCursor(0,0);

if (buttons & BUTTON_LEFT) {
    desiredTime--;
    lcd.print("Temp: ");
    lcd.setCursor(6, 0);
    lcd.print(desiredTemp);
    lcd.setCursor(9,0);
    lcd.print("C");
    lcd.setCursor(0,1);
    lcd.print("Time: ");
    lcd.setCursor(6,1);
    lcd.print(desiredTime);
    lcd.setCursor(9,1);
    lcd.print("min");
  
}  
    
    if (buttons & BUTTON_UP) {
    desiredTemp++;
    lcd.print("Temp: ");
    lcd.setCursor(6, 0);
    lcd.print(desiredTemp);
    lcd.setCursor(9,0);
    lcd.print("C");
    lcd.setCursor(0,1);
    lcd.print("Time: ");
    lcd.setCursor(6,1);
    lcd.print(desiredTime);
    lcd.setCursor(9,1);
    lcd.print("min");
    }
    
    if (buttons & BUTTON_DOWN) {
    desiredTemp--;
    lcd.print("Temp: ");
    lcd.setCursor(6, 0);
    lcd.print(desiredTemp);
    lcd.setCursor(9,0);
    lcd.print("C");
    lcd.setCursor(0,1);
    lcd.print("Time: ");
    lcd.setCursor(6,1);
    lcd.print(desiredTime);
    lcd.setCursor(9,1);
    lcd.print("min");
    }
 
    
    if (buttons & BUTTON_RIGHT) {
         desiredTime++;
    lcd.print("Temp: ");
    lcd.setCursor(6, 0);
    lcd.print(desiredTemp);
    lcd.setCursor(9,0);
    lcd.print("C");
    lcd.setCursor(0,1);
    lcd.print("Time: ");
    lcd.setCursor(6,1);
    lcd.print(desiredTime);
    lcd.setCursor(9,1);
    lcd.print("min");
    }
    
    if (buttons & BUTTON_SELECT) {

buttonPresses++;

  if (buttonPresses == 4)
   {buttonPresses = 0;}         // rollover every third press
    
    if (buttonPresses == 1 & buttonPresses != 2 & buttonPresses != 3 & buttonPresses != 0); { 
    if (lastPressCount not_eq buttonPresses) {   
    lcd.print("Temp: ");
    lcd.setCursor(6, 0);
    lcd.print(desiredTemp);
    lcd.setCursor(9,0);
    lcd.print("C");
    lcd.setCursor(0,1);
    lcd.print("Time: ");
    lcd.setCursor(6,1);
    lcd.print(desiredTime);
    lcd.setCursor(9,1);
    lcd.print("min");
   
//to scroll text
    delay(2000); //time until scroll starts
    //lcd.setCursor(16,1);  
    for(int positionCounter = 0; positionCounter < 16; positionCounter++) { 
    lcd.scrollDisplayLeft();
    
    delay(10); //velocity of scroll
    }
    lcd.setCursor(16,0); //where new text prints
    lcd.print("Press SELECT");
    lcd.setCursor(16,1);
    lcd.print("to start brewing");

//scroll back
     delay(2000); //time until scroll starts
    
    for(int positionCounter = 0; positionCounter < 16; positionCounter++) { 
    lcd.scrollDisplayRight();
    
    delay(1); //velocity of scroll
    }
    lcd.print("Temp: ");
    lcd.setCursor(6, 0);
    lcd.print(desiredTemp);
    lcd.setCursor(9,0);
    lcd.print("C");
    lcd.setCursor(0,1);
    lcd.print("Time: ");
    lcd.setCursor(6,1);
    lcd.print(desiredTime);
    lcd.setCursor(9,1);
    lcd.print("min");
  
 }
    }
  

  if (buttonPresses == 2)  {
    if (lastPressCount not_eq buttonPresses) {
    lcd.clear();
    lcd.setCursor(0,0);
    delay(250);
    lcd.print("Heating");
    lcd.setCursor(0,1);
    lcd.print("Temp: ");
    lcd.setCursor(6,1);
    lcd.print(Temperature); //prints temperature
  }
  }
  
  if (buttonPresses == 3)  {
    if (lastPressCount not_eq buttonPresses) {
    lcd.clear();
    lcd.setCursor(0,0);
    delay(250);
    lcd.print("Mashing");
  }
  }

  lastPressCount = buttonPresses;    // track last press count
 }
 }
 }

Try counting the presses then use a “switch case” statement to display the particular msg.

Count presses

switch (var) {
case 1:
//do something when var equals 1
break;
case 2:
//do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}

Weedpharma

Thanks for your reply! I tried your example, but probably understood something wrong. I added it like this:

if (buttons & BUTTON_SELECT) {
buttonPresses++;
switch (buttonPresses) {
case 1:
lcd.print("start");
break;
case 2:
lcd.print("heating");
break;
default:
lcd.print("mashing");
break;
}
}

This prints mashing to the screen all the time, no matter how many times I press the SELECT button. Could you see what I have been doing wrong?

(buttonPresses is zero above in the code as you can see in the code I first printed

You need to have a timer when counting the presses. This pseudocode may help.

If button pressed
Wait for button to be released
Increment count
Start timer
While timer is less than set time
If button pressed
Wait for button to be released
Increment count

Switch (counter)
Case 1
Print first message

Etc

Weedpharma