loopCounter.ino (1328B)
1 #include <Keypad.h> 2 3 4 const byte ROWS = 4; //four rows 5 const byte COLS = 3; //three columns 6 char keys[ROWS][COLS] = { 7 {'1','2','3'}, 8 {'4','5','6'}, 9 {'7','8','9'}, 10 {'*','0','#'} 11 }; 12 byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad 13 byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad 14 15 Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 16 17 unsigned long loopCount = 0; 18 unsigned long timer_t = 0; 19 20 void setup(){ 21 Serial.begin(9600); 22 23 // Try playing with different debounceTime settings to see how it affects 24 // the number of times per second your loop will run. The library prevents 25 // setting it to anything below 1 millisecond. 26 kpd.setDebounceTime(10); // setDebounceTime(mS) 27 } 28 29 void loop(){ 30 char key = kpd.getKey(); 31 32 // Report the number of times through the loop in 1 second. This will give 33 // you a relative idea of just how much the debounceTime has changed the 34 // speed of your code. If you set a high debounceTime your loopCount will 35 // look good but your keypresses will start to feel sluggish. 36 if ((millis() - timer_t) > 1000) { 37 Serial.print("Your loop code ran "); 38 Serial.print(loopCount); 39 Serial.println(" times over the last second"); 40 loopCount = 0; 41 timer_t = millis(); 42 } 43 loopCount++; 44 if(key) 45 Serial.println(key); 46 }