#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
char keys[ROWS][COLS] = { // Define the Keymap
{'D','C','B','A'},
{'#','9','6','3'},
{'0','8','5','2'},
{'*','7','4','1'}
};
byte rowPins[ROWS] = { 2, 3, 4, 5 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8 ,9}; // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );// Create the Keypad
void setup()
{
Serial.begin(9600);
Serial.println("Starting");
}
void loop()
{
char key = kpd.getKey();
if(key) // Check for a valid key.
{
switch (key)
{
case '1':
Serial.println("You've pressed one");
digitalWrite(10, HIGH);
delay(3000);
digitalWrite(10, LOW);
break;
case '2':
Serial.println("You've pressed two");
digitalWrite(11, HIGH);
delay(3000);
digitalWrite(11, LOW);
break;
case '3':
Serial.println("You've pressed three");
digitalWrite(12, HIGH);
delay(3000);
digitalWrite(12, LOW);
break;
case '4':
Serial.println("You've pressed four");
digitalWrite(13, HIGH);
delay(3000);
digitalWrite(13, LOW);
break;
case '5':
Serial.println("You've pressed five");
digitalWrite(22, HIGH);
delay(3000);
digitalWrite(22, LOW);
break;
case '6':
Serial.println("You've pressed six");
digitalWrite(24, HIGH);
delay(3000);
digitalWrite(24, LOW);
break;
case '7':
Serial.println("You've pressed seven");
digitalWrite(26, HIGH);
delay(3000);
digitalWrite(26, LOW);
break;
case '8':
Serial.println("You've pressed eight");
digitalWrite(28, HIGH);
delay(3000);
digitalWrite(28, LOW);
break;
case '9':
Serial.println("You've pressed nine");
digitalWrite(30, HIGH);
delay(3000);
digitalWrite(30, LOW);
break;
case '0':
Serial.println("You've pressed zero");
digitalWrite(32, HIGH);
delay(3000);
digitalWrite(32, LOW);
break;
default:
Serial.println(key);
}
}
}
Comments