Loading...
Pages: [1]   Go Down
Author Topic: LCD keypad shield with arduino uno  (Read 880 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi... ]smiley

I have a lcd keypad shield http://www.robotshop.com/dfrobot-lcd-keypad-shield-arduino-1.html and Arduino uno. I want lcd keypad shield displays an integer value ranging from 0 to 100. UP and DOWN push button function to add and reduce the value of the integer. below is an example of coding that I do. my problem now is the push button on the lcd keypad shield is not function and lcd displays continuous count from 0-100 and looping back. how do I solve this problem?? I'm new in Arduino. Which reference language should I choose to enable my programming function as i desired?.any help is greatly appreciated smiley-grin.



#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


#define RG   0
#define UP   1
#define DW  2
#define LF   3
#define SEL  4



int adc_key_in;
int NUM_KEYS = 5;
int adc_key_val[5] ={30, 150, 360, 535, 760};                          
                    

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



void loop()
{
  
    int value;
    for(value = 0 ; value <= 100; value++)
    
    if(adc_key_in == UP)                  
    {                                      
     value++;
    }
    
    else if(adc_key_in == DW)            
    {      
     value=-1;
    }
    
    
    else
    {                                    
      lcd.setCursor(0,0);                        
      lcd.print("COUNT:");
      lcd.setCursor(0,1);
      lcd.print(value);
      delay(1000);
  
    }
}
  

int get_key(unsigned int input)
{
   int k;
    
   for (k = 0; k < NUM_KEYS; k++)
   {
      if (input < adc_key_val[k])
      {
                return k;
                }
   }
    
    if (k >= NUM_KEYS)
        k = -1;     // No valid key pressed
    
    return k;
}



Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 96
Posts: 6331
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You forgot to call get_key():
Code:
void loop()
{
    int value;
    adc_key_in = get_key(analogRead(A0));   // Add this line
Logged

Central MN, USA
Offline Offline
Faraday Member
**
Karma: 35
Posts: 5913
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Even with John's suggestion, your program will not do what you want it to do. What is the business of the "for" loop?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You forgot to call get_key():
Code:
void loop()
{
    int value;
    adc_key_in = get_key(analogRead(A0));   // Add this line

thank you..it helped. but my purpose is to enable push button increase and decrease the integer value. my coding only showing the count. any other suggestion?. sorry im new in this arduino.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Even with John's suggestion, your program will not do what you want it to do. What is the business of the "for" loop?

i just want to set the integer value..., i think the control structure "for" might help.. smiley-grin. is it wrong??
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 96
Posts: 6331
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop()
{
    static int value = 0;   // If it isn't 'static' it gets created each time through loop().

    adc_key_in = get_key(analogRead(A0));   // Read the keypad

    if(adc_key_in == UP)                 
    {                                     
     value = constrain(value+1,0,100);
    }
    else if(adc_key_in == DW)           
    {       
     value = constrain(value-1,0,100);
    }
                               
      lcd.setCursor(0,0);                       
      lcd.print("COUNT:");
      lcd.setCursor(0,1);
      lcd.print(value);

      delay(250);   // wait 1/4 second before checking the keypad again
}
 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you so much sir for helping me...these coding helped me a lot.!!! i really appreciate it. smiley-yell
Logged

Central MN, USA
Offline Offline
Faraday Member
**
Karma: 35
Posts: 5913
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i just want to set the integer value..., i think the control structure "for" might help.. smiley-grin. is it wrong??

I think not. The for loop, if you have first read what a for loop does before writing with it, only increments your value from 0 to 101 and that is without looking at what your buttons are doing.

You will not likely use a for loop in this project (if it is just about incrementing numbers on LCD). John's code will get you started, not finished. Read about while loop if you want your project finished.
Logged


Pages: [1]   Go Up
Print
 
Jump to: