X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=hardware%2Fkeypad%2Fkeypad.ino;fp=hardware%2Fkeypad%2Fkeypad.ino;h=96796d8156f1ab64f63a408a641c52d39db8139e;hb=f1049e58baf973e21c716ef697458b1384f02b78;hp=0000000000000000000000000000000000000000;hpb=8bbff1c558947ca1ff1733240827c87494ff4fd5;p=sketchbook_andrea diff --git a/hardware/keypad/keypad.ino b/hardware/keypad/keypad.ino new file mode 100644 index 0000000..96796d8 --- /dev/null +++ b/hardware/keypad/keypad.ino @@ -0,0 +1,67 @@ +/* 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 + +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() +{ + pinMode(ledpin,OUTPUT); + 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); + } + } +} +