I recently ordered this keypad: http://www.abra-electronics.com/products/TEL%252dKEY-Keypad%252d-12-Buttons.html
Unfortunately, it has 8 pins while every tutorial I find only has code for 7 pins, which make more sense. I am unsure what the 8th pin is for and the 7 pin code doesn't even come close to working for my keypad. Here's the code I'm currently using:
#include <Keypad.h>
char* secretCode = "1234";
int position = 0;
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows] = {4, 5, 6, 7};
byte colPins[cols] = {1, 2, 3};
Keypad keypad = Keypad(makeKeymap(keys),
rowPins, colPins,
rows, cols);
int redPin = 12;
int greenPin = 13;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
setLocked(true);
}
void loop()
{
char key = keypad.getKey();
if (key == '*' || key == '#') {
position = 0;
setLocked(true);
}
if (key == secretCode[position]) {
position++;
}
if (position == 6) {
setLocked(false);
}
delay(50);
}
void setLocked(int locked)
{
if (locked) {
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
}
else {
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
}
}
I'm very inexperienced with this code and may have bitten off more than I could chew. Any help you can provide would be much appreciated as I am completely lost and need to figure this out. Right now when I upload the code with everything wired up the red LED stays on permanently, no matter what button I press.
Thanks!