LCD Code issues

Hi all,

I'm teaching myself how to code while I work on this project and would like an idea as to where i should go with this section. Just looking for something as maybe "hey try learning this or these commands to make it work." Here is what I am trying to accomplish.

I have an 2x16 LCD on I2C bus and 2 position switch. The switch is basically 2 stages, a gentle push then a more firm push. both are N.C. So if you press it hard both switches should show open, but there is the possibility of internal failure so that there is a possibility that you can have the following closed, closed / open, open / open, closed / closed, open.

I would like the title of the test to remain on line 1 of the LCD and status indicators on the second line.
the code works well if I put a delay in but I do not want to incorporate a delay as it interfers with the rest of my code. and it's not pretty at all on the LCD as it just flashes insanely fast if I do not put a delay. Any ideas, suggestions or questions will be welcomed and answered. This is the section of code I am working. I will do a follow up post with the full code. Thank you in advance.

 while ((selVal >= 783) && (selVal <= 793))         // 4 O'CLOCK POSITION
    {
      lls1Val = digitalRead(lls1Pin);
      lls2Val = digitalRead(lls2Pin);
      lcdblue.setCursor (0,0);           
      lcdblue.print("LOWER LMT SWITCH");  
        if ((lls1Val == HIGH) && (lls2Val == HIGH))
          {lcdblue.setCursor (0,1);
          lcdblue.print(" 1            1 ");}
          delay (500);
        if ((lls1Val == HIGH) && (lls2Val == LOW))
          {lcdblue.setCursor (0,1);
          lcdblue.print(" 1            0 ");}
          delay (500);
        if ((lls1Val == LOW) && (lls2Val == HIGH))
          {lcdblue.setCursor (0,1);
          lcdblue.print(" 0            1 ");}
        else 
          {lcdblue.setCursor (0,1);
          lcdblue.print(" 0            0 ");}     
    break;}

As stated the full code is here. It's an Arduino Mega 2560 if anyone is wondering.

It's fairly large and the forum will not allow me to put it in the code brackets.

Forum_test.ino (10.3 KB)

the code works well if I put a delay in but I do not want to incorporate a delay as it interfers with the rest of my code.

use millis() timing instead of delay()

See Several things at the same time and the BlinkWithoutDelay example in the IDE

Thank you I'll look into these tonight and see what I can do with them.

So this is what I have come up with. It still "flickers" when the switches are high. but now it only flickers the one that is high. it happens so fast that the lcd still shows "0" and not a 1.

here is the updated section.

while ((selVal >= 783) && (selVal <= 793))         // 4 O'CLOCK POSITION LOWER LIMIT TEST
    {
      lls1Val = digitalRead(lls1Pin);
      lls2Val = digitalRead(lls2Pin);
      unsigned long currentMillis = millis();
      lcdblue.setCursor (0,0);           
      lcdblue.print("LOWER LMT SWITCH");  
      lcdblue.setCursor (0,1);
        if ((currentMillis - previousMillis >= interval) && ((lls1Val == HIGH) && (lls2Val == HIGH)))
          {previousMillis = currentMillis;
          lcdblue.print(" 1            1 ");}
        if ((currentMillis - previousMillis >= interval) && ((lls1Val == HIGH) && (lls2Val == LOW)))
          {previousMillis = currentMillis;
          lcdblue.print(" 1            0 ");}
        if ((currentMillis - previousMillis >= interval) && ((lls1Val == LOW) && (lls2Val == HIGH)))
          {previousMillis = currentMillis;
          lcdblue.print(" 0            1 ");}
        else 
          {lcdblue.print(" 0            0 ");}     
    break;}

YES!!!
Success, I got the desired results I wanted though it might not be the best way. it does work.

while ((selVal >= 783) && (selVal <= 793))         // 4 O'CLOCK POSITION LOWER LIMIT TEST
    {
      lls1Val = digitalRead(lls1Pin);
      lls2Val = digitalRead(lls2Pin);
      lcdblue.setCursor (0,0);           
      lcdblue.print("LOWER LMT SWITCH");  
      lcdblue.setCursor (0,1);
        while ((lls1Val == HIGH) && (lls2Val == HIGH))
          {lcdblue.print(" 1            1 ");
          break;}
        while ((lls1Val == HIGH) && (lls2Val == LOW))
          {lcdblue.print(" 1            0 ");
          break;}
        while ((lls1Val == LOW) && (lls2Val == HIGH))
          {lcdblue.print(" 0            1 ");
          break;}            
        while ((lls1Val == LOW) && (lls2Val == LOW))
          {lcdblue.print(" 0            0 ");
          break;}
    break;}