]> git.piffa.net Git - sketchbook_andrea/blob - hardware/keypad/keypad.ino
RF e keypad
[sketchbook_andrea] / hardware / keypad / keypad.ino
1 /*  Keypadtest.pde
2  *
3  *  Demonstrate the simplest use of the  keypad library.
4  *
5  *  The first step is to connect your keypad to the
6  *  Arduino  using the pin numbers listed below in
7  *  rowPins[] and colPins[]. If you want to use different
8  *  pins then  you  can  change  the  numbers below to
9  *  match your setup.
10  *
11  */
12 #include <Keypad.h>
13
14 const byte ROWS = 4; // Four rows
15 const byte COLS = 3; // Three columns
16 // Define the Keymap
17 char keys[ROWS][COLS] = {
18   {
19     '1','2','3'  }
20   ,
21   {
22     '4','5','6'  }
23   ,
24   {
25     '7','8','9'  }
26   ,
27   {
28     '#','0','*'  }
29 };
30 // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
31 byte rowPins[ROWS] = { 
32   9, 8, 7, 6 };
33 // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
34 byte colPins[COLS] = { 
35   12, 11, 10 }; 
36
37 // Create the Keypad
38 Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
39
40 #define ledpin 13
41
42 void setup()
43 {
44   pinMode(ledpin,OUTPUT);
45   digitalWrite(ledpin, HIGH);
46   Serial.begin(9600);
47 }
48
49 void loop()
50 {
51   char key = kpd.getKey();
52   if(key)  // Check for a valid key.
53   {
54     switch (key)
55     {
56     case '*':
57       digitalWrite(ledpin, LOW);
58       break;
59     case '#':
60       digitalWrite(ledpin, HIGH);
61       break;
62     default:
63       Serial.println(key);
64     }
65   }
66 }
67