Go Down

Topic: Using keypad to scroll. HELP PLEASE (Read 1 time) previous topic - next topic

jacobblue

hey i'm using a 16x2 LCD and 3x4 matrix keypad. I've programmed an external button to be pressed if i wanted to scroll through pages in my LCD. But is there a way that i can program, where i can use my keypad keys such as "#" or "*" to scroll through my pages? i tried several ways to use them but i can't. Any help would be greatly appreciated:) thanks in advance

Code: [Select]
void loop() {
 

 currentButton = debounce(lastButton);
 if (lastButton == LOW && currentButton == HIGH)
 {
   {
   ds += 1;
 }
 if (ds >= 4){
   ds=1;
 }
 if (ds == 1){
   //write the stuffs required for page 1
   lcd.setCursor(0,0);
   lcd.print("HOME PAGE        ");
   
   lcd.setCursor(0,1);
   lcd.print("T/I= ");
   lcd.setCursor(6,1);
   lcd.print("NOT=  ");
   lcd.noBlink();
   
   
 }
 if (ds == 2){
   //write the stuffs required for page 2
   lcd.setCursor(0,0);
   lcd.print(" Set Interval:   ");
   lcd.setCursor(0,1);
   lcd.print("           ");
   lcd.setCursor(0,1);
   lcd.blink();
}
 if (ds == 3){
   //write the stuffs required for page 3
   lcd.setCursor(0,0);
   lcd.print("Set No.of Times:");
   lcd.setCursor(0,1);
 
   lcd.print("          ");
   lcd.setCursor(0,1);
   lcd.blink();
 }
   
 }
 lastButton = currentButton;

PaulS

Snippets are us is down the road a ways. Here, we need to see all the code.

Quote
i tried several ways to use them but i can't.

So you posted a snippet of code that has nothing to do with an attempt to use the * and # keys on the keypad. Why?

Using Tools + Auto Format before posting code (at least you did that properly) would be a good idea. As would consistent placement of curly braces. I prefer the "on a line by themselves" placement, myself. Others don't.

When there are mutually exclusive blocks of code, if/else if/else works better than if/if/if

jacobblue

That code is the one i used when i used an external button.
Code: [Select]
key = keypad.getKey();
 
  if (key == '*' )
  {
    {
      ds+=1;
    }
    if (ds >=4)
    {
      ds=1;
    }
    if(ds ==1){
    //write the stuffs required for page 1
    lcd.setCursor(0,0);
    lcd.print("HOME PAGE        ");
   
    lcd.setCursor(0,1);
    lcd.print("T/I= ");
    lcd.setCursor(6,1);
    lcd.print("NOT=  ");
    lcd.noBlink();
   
   
  }
  if (ds == 2){
    //write the stuffs required for page 2
    lcd.setCursor(0,0);
    lcd.print(" Set Interval:   ");
    lcd.setCursor(0,1);
    lcd.print("           ");
    lcd.setCursor(0,1);
    lcd.blink();
}
  if (ds == 3){
    //write the stuffs required for page 3
    lcd.setCursor(0,0);
    lcd.print("Set No.of Times:");
    lcd.setCursor(0,1);
   
    lcd.print("          ");
    lcd.setCursor(0,1);
    lcd.blink();
  }
   
  }

this is the one i used to try the key '*'
but it just runs one cycle only, i can't scroll multiple times.

PaulS

Quote
this is the one i used to try the key '*'
but it just runs one cycle only, i can't scroll multiple times.

What does multiple mean? How would the Arduino know when to quit scrolling? What does "scroll" mean, exactly?

It looks like each time you press a key, you want to change what is displayed on the LCD. I don't understand how that relates to scrolling.

jacobblue

yeah I meant the LCD displaying different things, each time i press. But how do i do that with a '*' key rather than an external button?

PaulS

Quote
But how do i do that with a '*' key rather than an external button?

You want the value of ds to increment by 1 each time you press the '*' key?

It looks like it is doing that now. Though, to be honest, the extra braces and poor indenting are making it hard to tell.

Code: [Select]
    {
      ds+=1;
    }

No braces needed.

Use Tools + Auto Format to fix the indenting.

Also, adjusting the value of ds and using ds are completely unrelated activities. Putting the code to use ds inside the block that detects a keypress and decides that it is a '*' is wrong.

jacobblue

oh sorry about the number of 'if's and brackets  used, i myself got confused sometimes. thank you for the help, i will try it tomorrow and let you know.
so are there any better ways to program this?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy