|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
-
-
- #include <Keypad.h>
-
- 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] = {5, 4, 3, 2};
- byte colPins[COLS] = {8, 7, 6};
-
- Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
-
- unsigned long loopCount;
- unsigned long startTime;
- String msg;
-
-
- void setup() {
- Serial.begin(9600);
- loopCount = 0;
- startTime = millis();
- msg = "";
- }
-
-
- void loop() {
- loopCount++;
- if ( (millis()-startTime)>5000 ) {
- Serial.print("Average loops per second = ");
- Serial.println(loopCount/5);
- startTime = millis();
- loopCount = 0;
- }
-
-
-
- if (kpd.getKeys())
- {
- for (int i=0; i<LIST_MAX; i++)
- {
- if ( kpd.key[i].stateChanged )
- {
- switch (kpd.key[i].kstate) {
- case PRESSED:
- msg = " PRESSED.";
- break;
- case HOLD:
- msg = " HOLD.";
- break;
- case RELEASED:
- msg = " RELEASED.";
- break;
- case IDLE:
- msg = " IDLE.";
- }
- Serial.print("Key ");
- Serial.print(kpd.key[i].kchar);
- Serial.println(msg);
- }
- }
- }
- }
|