I was looking through the sparkfun website and found these keypad matrices....

which allow each button to be individually lit by an led. i've decided to use a keypad encoder to limit the number of pins i need to use to run it, so i have a couple of 74C922 keypad encoders on order from Farnell. heres the data sheet http://www.elexp.com/tips/74C922.pdf
the idea is that the 74C922 ic reads the key pad matrix, and when a button is pressed, it sends a logic signal via the data pin to the arduino, which tells the arduino to read the four input pins from the 74C922 and to save these inputs as a 4 digit binary number. this 4 digit binary number relates to one of the 16 buttons on the keypad.
so far i have written this code, that reads the data pin, and if its HIGH, then it switches on an led on pin 13, and then reads the input pins and prints the data to the serial connection.
int dataPin = 2; // data pin
int in1Pin = 3; // input pin 1
int in2Pin = 4; // input pin 2
int in3Pin = 5; // input pin 3
int in4Pin = 6; // input pin 4
int ledPin = 13; // led pin
int val = 0;
void setup() {
pinMode(dataPin, INPUT); // declare pins as input or output
pinMode(in1Pin, INPUT);
pinMode(in2Pin, INPUT);
pinMode(in3Pin, INPUT);
pinMode(in4Pin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // begin serial
}
void loop() {
val = digitalRead(dataPin); // read data pin value
if (val == HIGH) { // if HIGH
digitalWrite(ledPin, HIGH); // switch on led pin
digitalRead(in1Pin); // read inputs
digitalRead(in2Pin);
digitalRead(in3Pin);
digitalRead(in4Pin);
Serial.print(in1Pin, BYTE); // print inputs to serial connection
Serial.print(in2Pin, BYTE);
Serial.print(in3Pin, BYTE);
Serial.print(in4Pin, BYTE);
} else {
digitalWrite(ledPin, LOW); // if data pin LOW, switch off led pin, and do nothing.
}
}
it complies fine, but is so far untested as i dont have the parts yet. what i would like to do is to hold the 4 digit binary number as a string, then print to the serial port. at the moment i think this code will print each input byte individually, but i dont really understand how to store it as a string just yet.
so, any comments or ideas to make it run smoother?
cheers,
bod.
