PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

79 行
2.1KB

  1. /* @file MultiKey.ino
  2. || @version 1.0
  3. || @author Mark Stanley
  4. || @contact mstanley@technologist.com
  5. ||
  6. || @description
  7. || | The latest version, 3.0, of the keypad library supports up to 10
  8. || | active keys all being pressed at the same time. This sketch is an
  9. || | example of how you can get multiple key presses from a keypad or
  10. || | keyboard.
  11. || #
  12. */
  13. #include <Keypad.h>
  14. const byte ROWS = 4; //four rows
  15. const byte COLS = 3; //three columns
  16. char keys[ROWS][COLS] = {
  17. {'1','2','3'},
  18. {'4','5','6'},
  19. {'7','8','9'},
  20. {'*','0','#'}
  21. };
  22. byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the kpd
  23. byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd
  24. Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  25. unsigned long loopCount;
  26. unsigned long startTime;
  27. String msg;
  28. void setup() {
  29. Serial.begin(9600);
  30. loopCount = 0;
  31. startTime = millis();
  32. msg = "";
  33. }
  34. void loop() {
  35. loopCount++;
  36. if ( (millis()-startTime)>5000 ) {
  37. Serial.print("Average loops per second = ");
  38. Serial.println(loopCount/5);
  39. startTime = millis();
  40. loopCount = 0;
  41. }
  42. // Fills kpd.key[ ] array with up-to 10 active keys.
  43. // Returns true if there are ANY active keys.
  44. if (kpd.getKeys())
  45. {
  46. for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
  47. {
  48. if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
  49. {
  50. switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
  51. case PRESSED:
  52. msg = " PRESSED.";
  53. break;
  54. case HOLD:
  55. msg = " HOLD.";
  56. break;
  57. case RELEASED:
  58. msg = " RELEASED.";
  59. break;
  60. case IDLE:
  61. msg = " IDLE.";
  62. }
  63. Serial.print("Key ");
  64. Serial.print(kpd.key[i].kchar);
  65. Serial.println(msg);
  66. }
  67. }
  68. }
  69. } // End loop