I have a Corby 7020 keypad (looks a lot like one of those coded garage-door openers' keypads) and I've been trying to hook it up to my Duemilanove. Hardware-wise, everything's a go: I found out what each pin on the back of the keypad does, and I've connected it to the Arduino via a breadboard.
However, I'm not sure how to read each of my 12 pins for a charge. So far, I have:
void setup() {
for (int i = 0; i < 12; i++)
{
sense = i;
_ pinMode(sense*, INPUT);_
_ } _
_ Serial.begin(9600);_
_}_ void loop(){
_ for (int j = 13; j > 0; j--)_
_ {_
_ buttonState[j] = digitalRead(sense[j]);_
_ Serial.print(buttonState[j]);_
_ Serial.print(" ");_
_ }_
_ Serial.println();_
_}_
_[/font]_ but it only gives me a value of 1 or 0, seemingly randomly. Any pointers would be greatly appreciated! Thanks so much!
_(PS: This is a great code for seeming like a brilliant programmer because the output scrolls down the screen Matrix-style. Just in case you're interested.)*_
The sense and buttonState arrays are defined to hold 12 values. That means that the indexes range from 0 to 11. When j is 13 or 12, you are reading/writing out of bounds.
Some description about how you have connected the keypad would be useful. Typically, these things do not act like 12 individual buttons in one housing. The rows and columns have to be set/read in turn (quickly) to read a keypress.
Oh wow, thanks for that catch, I completely missed that! (Incidentally, the backwards incrementation was so that the printout was in the same order as the pins on my arduino, which leads me to---)
Layout:
I tested the entire board for continuity -- it's a 3x4 board, with 123, 456, 789, *0# on their respective lines. There are 13 pins on the back of the pad, twelve of which correspond to the buttons (I tested for continuity) and the thirteenth of which is a common 'other end' of the circuit. Basically, pressing [1] connects Pin 0 to Pin 1, pressing [2] connects 0 and 2, and so on. I know there are better ways, but I connected each of the twelve pins to an individual Digital Pin, and the 13th to 5V. I'm now just trying to figure out how to detect that 5V on each pin.
Have you connected pins from the keypad to digital pins 0 and 1 (implied by setting sense to i)? You can't use digital pins 0 and 1 for input at the same time you are using them for serial output.