16.2 lcd switchcase menu help

Hi ,

I am trying to with a button press change the number and display a different name on a lcd 16.2 I2c.
when i press the button it displays the name but doesn't display the default number. i would like it to display the number and the name ie 1 crunch, 2 lead, 3 drive, can someone tell me where i am going wrong.

Thank you

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int button = 4;
int count = 0;
int upLastTime, downLastTime, upNow, downNow;

void setup() {
 
lcd.begin(16,2);

pinMode (button,INPUT_PULLUP);



}

void loop() {
  upNow = digitalRead(button); 
 if (upNow == HIGH && upLastTime == LOW) { 
  lcd.setCursor(0,0);
  lcd.print(count++);
 
  switch (count) {
    case 1:
      lcd.setCursor(5,0);
      lcd.print(" clean");
      break;
    case 2:   
     //lcd.clear();
      lcd.setCursor(5,0);
      lcd.print(" Crunch");
      break;
    case 3:  
    //lcd.clear();
      lcd.setCursor(5,0);
      lcd.print(" Lead");
      break;
    case 4:    
      lcd.clear();
      lcd.setCursor(5,0);
      lcd.print("Drive");
      break;
      case 5:
     lcd.clear();
      break;
  }

    delay(20); // bit of debounce delay
 }
 upLastTime= upNow;  
  
  
  
}

Hi.

If you need the number, you need to print the number to your LCD like this:

     case 1:
      lcd.setCursor(5,0);
      lcd.print (count);
      lcd.print(" clean");
      break;
    case 2:   
     //lcd.clear();
      lcd.setCursor(5,0);
      lcd.print (count);
      lcd.print(" Crunch");
      break;

You have already added the necessary space in front of your text, so that should be OK.
In case your number of cases grow larger than 9, 99, or 999 (and so on) you might need to take some special consideration for the extra space you will probably need.

Thanks for that.

I have added some big custom numbers to the display, so it shows a custom number and a text name, one problem i am having is after the 2nd display number and name the text gets stuck ie instead of the display showing "3 Lead it displays 3 leadch or 4 drive it displays 4 driveh can some tell me how to fix this.
The code is as follows...

/*
 * customChars
 *
 * This sketch displays double-height digits
 * the bigDigit arrays were inspired by Arduino forum member dcb
 */
//#include <LiquidCrystal.h>
#include <Wire.h>

// 2. for the LCD functions
#include <LiquidCrystal_I2C.h>
int button = 4;
int count = 0;
int upLastTime, downLastTime, upNow, downNow;

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
byte glyphs[5][8] = {
  { B11111,B11111,B00000,B00000,B00000,B00000,B00000,B00000  } ,
  { B00000,B00000,B00000,B00000,B00000,B00000,B11111,B11111  } ,
  { B11111,B11111,B00000,B00000,B00000,B00000,B11111,B11111  } ,
  { B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111  } ,
  { B00000,B00000,B00000,B00000,B00000,B01110,B01110,B01110  } };
const int digitWidth = 3; // the width in characters of a big digit (excludes space between characters)
//arrays  to index into custom characters that will comprise the big numbers
// digits 0 - 4                             0      1       2      3      4
const char bigDigitsTop[10][digitWidth]={ 3,0,3, 0,3,32, 2,2,3, 0,2,3, 3,1,3,
// digits 5-9                               5      6      7        8      9
                                          3,2,2, 3,2,2, 0,0,3,   3,2,3, 3,2,3};
const char bigDigitsBot[10][ digitWidth]={ 3,1,3, 1,3,1,  3,1,1, 1,1,3, 32,32,3,
                                           1,1,3, 3,1,3, 32,32,3, 3,1,3, 1,1,3};
char buffer[12]; // used to convert a number into a string
void setup ()
{
  pinMode (button,INPUT_PULLUP);
  lcd.begin(16,2);
  lcd.setCursor(3, 0); // top left
  lcd.print("ENIGMA ver1");
  // create the custom glyphs
 for(int i=0; i < 5; i++)
   lcd.createChar(i, glyphs[i]);   // create the 5 custom glyphs
  // show a countdown timer
 // for(int digit = 9; digit >= 0; digit--)
  //{
    //showDigit(digit, 2);  // show the digit
    delay(1000);
 // }
  lcd.clear();
}


void loop ()
{
  upNow = digitalRead(button); 
 if (upNow == HIGH && upLastTime == LOW) { 
  //lcd.setCursor(0,0);
  //lcd.print(count++);
   //showNumber( count++, 0);
 int disp = count++;
  switch (disp) {
    case 0:
    //lcd.clear();
      lcd.setCursor(6,0);
      lcd.print("Clean");
      lcd.setCursor(0,0);
      showNumber(count,0);
      break;
    case 1:   
   // lcd.clear();
      lcd.setCursor(6,0);
      lcd.print("Crunch");
      lcd.setCursor(0,0);
      showNumber(count,0);
      break;
    case 2:  
   // lcd.clear();
      lcd.setCursor(6,0);
      lcd.print("Lead");
      lcd.setCursor(0,0);
      showNumber(count,0);
      break;
    case 3:    
     // lcd.clear();
      lcd.setCursor(6,0);
      lcd.print("Drive");
      showNumber(count,0);
      break;
   default:
   lcd.setCursor(5,0);
   lcd.clear();
   lcd.setCursor(0,0);
   showNumber(count,0);
     break;
   
 
 
  }

    delay(20); // bit of debounce delay
 }  
 upLastTime= upNow;  
  

  }

void showDigit(int digit, int position)
{
  lcd.setCursor(position * (digitWidth + 1), 0);
   for(int i=0; i < digitWidth; i++)
      lcd.print(bigDigitsTop[digit][i]);
   lcd.setCursor(position * (digitWidth + 1), 1);
   for(int i=0; i < digitWidth; i++)
      lcd.print(bigDigitsBot[digit][i]);
}
void showNumber(int value, int position)
{
 int index; // index to the digit being printed, 0 is the leftmost digit
    itoa(value, buffer, 10); // see Recipe 2.8 for more on using itoa
    // dislay each digit in sequence
    for(index = 0; index < 10; index++) // display up to ten digits
    {
      char c = buffer[index];
      if( c == 0)  // check for null (not the same as '0')
         return; // the end of string character is a null, see Chapter 2
      c = c - 48; // convert ascii value to a numeric value  (see Recipe 2.9)
      showDigit(c, position + index);
    }
}[code]

You need to keep track of what you have been doing, so you will be able to undo it.

Or just erase your entire screen right before you write new info to it.
And only do that if there is new info to write, don't keep rewriting info that's already displayed.

Thanks

Or just erase your entire screen right before you write new info to it.
And only do that if there is new info to write, don't keep rewriting info that's already displayed.

Should i be putting lcd.clear after each switch statement?

No, certainly not.
If you would do that in every case.., then there is no need to put that under any condition (which is what switch ... case is about), and do it before you go into the drop down the switch... shoot.

Read about 'blink without delay', as mentioned in my sign off message beneath every post i make (it is there with reason), and about doing 'several things at the same time'.
You will learn how to keep track of what you have been doing (involves a bit more memory), and do this kind of things the proper way.
All information about that can be found on these forums and you should have stumbled upon this, browsing the forums for the past 2 years.