how to incorporate "if" statement with lcd display

Hi guys,

I was wondering how you would creating an if statement if the Lcd is printing a certain letter in a certain position

for exmaple: { if ( lcd.setCursor(0,0) == "T") { lcd.setCursor(0,1); lcd.print("G"); } }

is something like this even possible?

cheers Guys, Jon

Like you want, no. But if you explain what you really want to do, maybe there’s is a way.
Other thing, when you post code, use the “code” tag in the tools bar.

#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
#include <TimeAlarms.h>
#include <Time.h>
#include <LiquidCrystal.h>
#include <SPI.h>

LiquidCrystal lcd(12,11,5,4,3,2);
int backLight = 10;
const int latchPin = 8;
const int dataPin = 9;
const int clockPin = 7;

byte switchVar1 = 0;

const int numRows = 4;
const int numCols = 20;
const byte Symbol_1 = B10110000;
const byte Symbol_2 = B01111110;

/*Switch Binary Number Reference
2 == Back
4 == Options 
8 == Ok
16 == Left
32 == Down
64 == Up 
129 == Right
*/

void setup()
{
  pinMode (backLight, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, INPUT);
  
  //RTC boot up
  Wire.begin();
  RTC.begin();
  
//lcd boot up screen
  digitalWrite(backLight, HIGH);
  lcd.begin(numCols,numRows);
  lcd.setCursor(6,0);
  lcd.print("WELCOME");
  lcd.setCursor(1,1);
  lcd.print("Dosing Pump Module");
  lcd.setCursor(5,2);
  lcd.print("By JUNBLUD");
  lcd.setCursor(4,3);
  lcd.print("Loading:");
  for (int i = 0; i <= 100; i++)
  {
    lcd.setCursor(12,3);
    if (i<100) lcd.print(" "); 
    if (i<10) lcd.print(" ");
    lcd.print(i);
    lcd.print("%");
    delay(100); 
  }
   delay(2000);
   lcd.clear();
}
   
void mainMenu()
{
  lcd.setCursor(0,0);
  lcd.print("Main Menu");
     lcd.setCursor(0,1);
     lcd.write(Symbol_1);
     lcd.setCursor(2,1);
     lcd.print("Pump 1");
       lcd.setCursor(0,2);
       lcd.write(Symbol_1);
       lcd.setCursor(2,2);
       lcd.print("Pump 2");
         lcd.setCursor(0,3);
         lcd.write(Symbol_1);
         lcd.setCursor(2,3);
         lcd.print("Set Schedule");
           lcd.setCursor(10,1);
           lcd.write(Symbol_1);
           lcd.setCursor(12,1);
           lcd.print("Pump 3");
    {
      DateTime now = RTC.now();
      lcd.setCursor(12,0);
      lcd.print(now.hour(), DEC);
      lcd.print(':');
      lcd.print(now.minute(), DEC);
      lcd.print(':');
      lcd.print(now.second(), DEC);
      delay(1000); 
    }
  } 
}

void shiftRegister()
{
  digitalWrite(backLight, HIGH);
  
  digitalWrite(latchPin, HIGH);
  delayMicroseconds(20);
  digitalWrite(latchPin, LOW);

  switchVar1 = shiftIn(dataPin, clockPin, MSBFIRST);
}

void loop()
{
  mainMenu();
  shiftRegister();
  {
    if (switchVar1 == 32)
    {
      lcd.setCursor(0,1);
      lcd.write(Symbol_2);
    }
  }
}

so What i am trying to do is create a Menu with the Lcd and using up down left right and ok buttons to be able to scroll through the main menu. by default each pump is bulleted by a dash and when you press the down button or up button (like scrolling through main menu, i want them to change to arrows. When the arrow is printed next to the pump you want you press ok and takes you to another menu( but that is for another day, lets just focus on getting the main menu done).

currently in the loop i call on the main menu function, then the shift register function which reads the binary input and prints to the lcd accordingly. However, as these functions are in a loop, the arrow disappears shortly after pressing as the loop has started again.

cheers,
Jon

Why don't you write what you want to be in the menu in a array, then write the array to the LCD. When you press a key you know that you must increment the index of the array to print the next element. To find out what are the text you have in the LCD you only must to know what index you are writing in the moment.

I have no idea where to start with that :( sorry :blush:

I have no idea where to start with that smiley-sad sorry smiley-red

Writing a menu is a pretty complex thing. I just went through it and documented pretty much what I have done. It’s a slight different purpose but you might get an idea where to start if you want to have a look …

wow thats awesome!

thanks for that :smiley: