hello im newbie but i can use thats code good, i test and working ok.
/*Program demonstrating 4x4 Numeric Keypad interfacing with Arduino UNO
Program Written by: Amit Biswal (Speaking Technology)
URL :
http://amitbiswal.blogspot.com */
int r1=A5;
int r2=A4;
int r3=A3;
int r4=A2;
int c1=A1;
int c2=A0;
int c3=10;
int c4=11;
void setup()
{
Serial.begin(9600);
pinMode(r1,OUTPUT);
pinMode(r2,OUTPUT);
pinMode(r3,OUTPUT);
pinMode(r4,OUTPUT);
pinMode(c1,INPUT);
pinMode(c2,INPUT);
pinMode(c3,INPUT);
pinMode(c4,INPUT);
}
void loop()
{
int val;
//setting the columns as high initially
digitalWrite(c1,HIGH);
digitalWrite(c2,HIGH);
digitalWrite(c3,HIGH);
digitalWrite(c4,HIGH);
//checking everything one by one
//case 1: col1 =0 while other col as 1
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
digitalWrite(r4,HIGH);
//checking each column for row1 one by one
if(digitalRead(c1)==0)
{
Serial.println("key 1 pressed");
}
else if(digitalRead(c2)==0)
{
Serial.println("Key 2 pressed");
}
else if(digitalRead(c3)==0)
{
Serial.println("Key 3 pressed");
}
else if(digitalRead(c4)==0)
{
Serial.println("Key A pressed");
}
//case 2: col2 =0 while other col as 1
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(r3,HIGH);
digitalWrite(r4,HIGH);
//checking each column for row1 one by one
if(digitalRead(c1)==0)
{
Serial.println("key 4 pressed");
}
else if(digitalRead(c2)==0)
{
Serial.println("Key 5 pressed");
}
else if(digitalRead(c3)==0)
{
Serial.println("Key 6 pressed");
}
else if(digitalRead(c4)==0)
{
Serial.println("Key B pressed");
}
//case 3: col3 =0 while other col as 1
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,LOW);
digitalWrite(r4,HIGH);
//checking each column for row1 one by one
if(digitalRead(c1)==0)
{
Serial.println("key 7 pressed");
}
else if(digitalRead(c2)==0)
{
Serial.println("Key 8 pressed");
}
else if(digitalRead(c3)==0)
{
Serial.println("Key 9 pressed");
}
else if(digitalRead(c4)==0)
{
Serial.println("Key C pressed");
}
//case 1: col1 =0 while other col as 1
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
digitalWrite(r4,LOW);
//checking each column for row1 one by one
if(digitalRead(c1)==0)
{
Serial.println("key F pressed");
}
else if(digitalRead(c2)==0)
{
Serial.println("Key 0 pressed");
}
else if(digitalRead(c3)==0)
{
Serial.println("Key E pressed");
}
else if(digitalRead(c4)==0)
{
Serial.println("Key D pressed");
}
//giving delay between keypress
delay(200);
}
but i have proplem, why next code no working,i load arduino examples at net and test better code but compiler stop alltime const byte row (and many many other error have too.why no working because must be have arduino examples code :O ????
this is examples code-->
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact
alexanderbrevig@gmail.com||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
}
}