Keypad problems.


i'm using 4x4 keypad jameco (this one) user input arduino mega. problem is, reading doesn't work @ all.
code: [select]

#include <wire.h>
#include <liquidcrystal_i2c.h>



#define i2c_addr      0x3f
#define backlight_pin 3
#define en_pin        2
#define rw_pin        1
#define rs_pin        0
#define d4_pin        4
#define d5_pin        5
#define d6_pin        6
#define d7_pin        7

#define kpc1          22
#define kpc2          24
#define kpc3          26
#define kpc4          28
#define kpr1          30
#define kpr2          32
#define kpr3          34
#define kpr4          36

liquidcrystal_i2c lcd(i2c_addr,en_pin,rw_pin,rs_pin,d4_pin,d5_pin,d6_pin,d7_pin, backlight_pin, positive);

int pl=0;
void setup()
{
 
 lcd.begin(20,4);
 serial.begin(9600);
 lcd.print("start");
 delay(1000);
 lcd.clear();
 lcd.home();
 pinmode(kpr1,output);
 pinmode(kpr2,output);
 pinmode(kpr3,output);
 pinmode(kpr4,output);
 pinmode(kpc1,input_pullup);
 pinmode(kpc2,input_pullup);
 pinmode(kpc3,input_pullup);
 pinmode(kpc4,input_pullup);
 for(int i=22;i<=36;i+=2){digitalwrite(i,low);}
}

void loop()
{
 digitalwrite(kpr1,high);
 delay(2);
 if(!digitalread(kpc2)){if(pl!=1){lcd.print("!");pl=1;}serial.println("!");}else{pl=0;lcd.clear();}
 digitalwrite(kpr1,low);
 delay(2);
}

currently, code (should) read first row, second column, so:
code: [select]

[ ][ ][ ][ ]
[ ][ ][ ][ ]
[ ][ ][ ][ ]
[ ][x][ ][ ]


pressing button i'm trying read affect output, many of other buttons, , of them seem latch it. ideas?

hi,

your setup() performing digitalwrite(low) on pins got set input_pullup. switch off internal pullups.

i suggest trying this: set row pins input without pullup in setup(). then, in loop(), switch 1 row @ time output , low, read columns , set row input.

paul


Arduino Forum > Using Arduino > Project Guidance > Keypad problems.


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support