Went to a Hamfest last week and found a matrix keypad for $2 so I figured I'd play with it.
I copied this code right from the arduino playground:
/* Keypadtest.pde
*
- Demonstrate the simplest use of the keypad library.
- The first step is to connect your keypad to the
- Arduino using the pin numbers listed below in
- rowPins[] and colPins[]. If you want to use different
- pins then you can change the numbers below to
- match your setup.
*/
#include <Keypad.h>const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10 };// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );#define ledpin = 13;
void setup()
{
digitalWrite(ledpin, HIGH);
Serial.begin(9600);
}void loop()
{
char key = kpd.getKey();
if(key) // Check for a valid key.
{
switch (key)
{
case '*':
digitalWrite(ledpin, LOW);
break;
case '#':
digitalWrite(ledpin, HIGH);
break;
default:
Serial.println(key);
}
}
}
I am having 2 problems
1: * and # are not showing up in the serial monitor but 1- 0 are.
2: The led does turn on and off when * or # is hit but it glows very dimmly. I thought the led on the UNO may be going bad so I switched to an external led hooked to another pin, but the same thing, very dim.
when I hit the reset button on the UNO the led on pin 13 does blink at full brightness....So I'm stumped.