Go Down

Topic: **HELP** changing pages on a 16x2 LCD with a button (Read 1 time) previous topic - next topic

Joy

My arduino is calculating multiple things ..
for example..
A, B, C, D, E


Now I have a 16x2 CLD connected to the arduino and I want to make some pages where only few of the things will be displayed
Like.

PAGE 1
A                   C
B                   D

PAGE 2
A                   E
B                   D

PAGE 3
Only E


Now I want to changes these pages one by one with a button..

How do I start this..??

Joy

I tried something like this..
Can this be made more easier ..??

Code: [Select]
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int switchPin = 8;   // momentary switch on 8, other side connected to ground
int Display = 0;

void setup()
{
 lcd.begin(16, 2);
 pinMode(switchPin, INPUT);
 digitalWrite(switchPin, HIGH);      // turn on pullup resistor
}

void loop()
{
 if (digitalRead(switchPin) == LOW){  
   delay(500);                        // delay to debounce switch

   Display = Display + 1;
   if(Display > 3){
     lcd.clear();
     Display = 1;
   }
   
   switch (Display) {
     case 1: {
       lcd.setCursor(0, 0);
       lcd.print("joy");
       
       break;
     }
       
     case 2: {
       lcd.clear();
       lcd.setCursor(1, 0);
       lcd.print("raha");
       break;
     }
       
      case 3: {
        lcd.clear();
        lcd.setCursor(1, 1);
        lcd.print("hkfl");
        break;
      }
 }
}
}

liudr

Yes you can. My question for you: are the A-E going to dynamically change as you switch screens or are they static once you start displaying them.

If they are static, use my phi_prompt library's scrollable long message and do something like:

simple_long_msg("A   B   \nC   D   \nE");

This will display all 5 things in a scrollable long message with a scroll bar on the right. Using up and down buttons you can scroll through them and press enter to dismiss the long message. Let me know if that is what you want. As I said, this can't handle dynamic updates as you scroll so A-E have to be determined by the time you call the function. Yes, the long message recognizes new line. ;)

Joy

All values A, B, C, D, E are continuously calculated by arduino and so they will change dynamically...

Joy

And please help me removing that delay for the button debounce... :( as it will effct the other loops... :P

jfhaugh


And please help me removing that delay for the button debounce... :( as it will effct the other loops... :P


You don't need a 500 millisecond delay.  Most switches are "done" bouncing within 50 to 100ms.

You can debounce a switch with a small capacitor, but you don't say how the circuit is built, so I won't recommend a value.  Changing that delay(500) to delay(50) should work.  Just remember that if you do that, you have to let go of the switch REALLY FAST or else the program will rapidly scroll through all of the screens ;)

Joy

ok i removed the delay and used a similar program like the one used in the example of "Blink without delay"

But I have kept the debounce rate 250..

But I dont want the thing that when the button is kept pressed the screens will scroll over..

I want it like if the display is showing screen 1, pressing the button shifts display to screen 2 but until and unless the button is released and pressed again there will be no change in the scree...

How do I do this...??

jfhaugh

Add a variable which says "the last time I checked, the button was pressed".  When that button is "true", don't change the page.

Then check to see if the button has been released and set that new variable to "false".  Don't forget to debounced the "button released" test as well ;)

liudr


All values A, B, C, D, E are continuously calculated by arduino and so they will change dynamically...


That was what I feared. Then my code won't help you. To make the buttons work the way you describe, you should record the button state in a variable and compare its value with reading to capture NOT the button in the down state, BUT capture the button changing from up to down TRANSITION.

Joy

can someone please show that to me with a small example...??

PaulS

Code: [Select]
int prevState = HIGH;
int currState;

void loop()
{
  currState = digitalRead(somePin);
  if(currState != prevState)
  {
    // A transition occurred (assuming that HIGH is not pressed and LOW is pressed).
  }
  prevState = currState;
}

Joy

I tried your way..
Code: [Select]
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 10, 9);

int switchPin = 19;   // momentary switch on 8, other side connected to ground
int Display = 0;
int prevstate = HIGH;
int currstate;

void setup()
{
  lcd.begin(16, 2);
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);      // turn on pullup resistor
}

void loop()
{
  currstate = digitalRead(switchPin);
  if (currstate != prevstate){ 
               

    Display = Display + 1;
    if(Display > 3){
      lcd.clear();
      Display = 1;
    }
  }

    switch (Display) {
      case 1: {
        lcd.setCursor(0, 0);
        lcd.print("joy");
        break;
      }
       
      case 2: {
        lcd.setCursor(5, 0);
        lcd.print("raha");
        break;
      }
       
       case 3: {
         lcd.setCursor(1, 1);
         lcd.print("hkfl");
         break;
       }
  }
   prevstate = currstate;
}



But this does not seems to work properly...
Please make corrections if I am making mistakes somewhere... :(

cyclegadget

What pin do you have the switch connected to?

Code: [Select]
int switchPin = 19;   // momentary switch on 8, other side connected to ground
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

Joy


What pin do you have the switch connected to?

Code: [Select]
int switchPin = 19;   // momentary switch on 8, other side connected to ground



Sorry...
Actually I have the button connected to A5..
So it will be actually

Code: [Select]
int switchPin = 19;   // momentary switch on A5, other side connected to ground

liudr

And how are you connecting the button on the breadboard? Makes a big difference between connecting it the right way and the wrong way. Need diagram or description.

Go Up