Misc files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PolyPad_Teensy_2.0.ino 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Buttons to USB Keyboard Example - Special Media Player Keys
  2. You must select Keyboard from the "Tools > USB Type" menu
  3. This example code is in the public domain.
  4. */
  5. #include <Bounce.h>
  6. // Create Bounce objects for each button. The Bounce object
  7. // automatically deals with contact chatter or "bounce", and
  8. // it makes detecting changes very simple.
  9. Bounce MX01 = Bounce(4, 10);
  10. Bounce MX02 = Bounce(5, 10); // 10 ms debounce time is appropriate
  11. Bounce MX03 = Bounce(6, 10); // for most mechanical pushbuttons
  12. Bounce MX04 = Bounce(7, 10);
  13. Bounce MX05 = Bounce(9, 10); // if a button is too "sensitive"
  14. Bounce MX06 = Bounce(10, 10); // you can increase this time.
  15. Bounce MX07 = Bounce(17, 10);
  16. Bounce MX08 = Bounce(16, 10);
  17. Bounce MX09 = Bounce(15, 10);
  18. Bounce MX10 = Bounce(14, 10);
  19. Bounce MX11 = Bounce(12, 10);
  20. Bounce MX12 = Bounce(11, 10);
  21. void setup() {
  22. // Configure the pins for input mode with pullup resistors.
  23. // The pushbuttons connect from each pin to ground. When
  24. // the button is pressed, the pin reads LOW because the button
  25. // shorts it to ground. When released, the pin reads HIGH
  26. // because the pullup resistor connects to +5 volts inside
  27. // the chip.
  28. pinMode(4, INPUT_PULLUP);
  29. pinMode(5, INPUT_PULLUP);
  30. pinMode(6, INPUT_PULLUP);
  31. pinMode(7, INPUT_PULLUP);
  32. pinMode(9, INPUT_PULLUP);
  33. pinMode(10, INPUT_PULLUP);
  34. pinMode(17, INPUT_PULLUP);
  35. pinMode(16, INPUT_PULLUP);
  36. pinMode(15, INPUT_PULLUP);
  37. pinMode(14, INPUT_PULLUP);
  38. pinMode(12, INPUT_PULLUP);
  39. pinMode(11, INPUT_PULLUP);
  40. pinMode(8, OUTPUT); // The virtual Ground Pin
  41. digitalWrite(8, LOW);
  42. }
  43. void loop() {
  44. // Update all the buttons. There should not be any long
  45. // delays in loop(), so this runs repetitively at a rate
  46. // faster than the buttons could be pressed and released.
  47. MX01.update();
  48. MX02.update();
  49. MX03.update();
  50. MX04.update();
  51. MX05.update();
  52. MX06.update();
  53. MX07.update();
  54. MX08.update();
  55. MX09.update();
  56. MX10.update();
  57. MX11.update();
  58. MX12.update();
  59. // Check each button for "falling" edge.
  60. // falling = high (not pressed - voltage from pullup resistor)
  61. // to low (pressed - button connects pin to ground)
  62. if (MX01.fallingEdge()) {
  63. Keyboard.press(KEY_HOME);
  64. Keyboard.release(KEY_HOME);
  65. }
  66. if (MX02.fallingEdge()) {
  67. Keyboard.press(KEY_UP);
  68. Keyboard.release(KEY_UP);
  69. }
  70. if (MX03.fallingEdge()) {
  71. Keyboard.press(KEY_PAGE_UP);
  72. Keyboard.release(KEY_PAGE_UP);
  73. }
  74. if (MX04.fallingEdge()) {
  75. Keyboard.press(KEY_LEFT);
  76. Keyboard.release(KEY_LEFT);
  77. }
  78. if (MX05.fallingEdge()) {
  79. Keyboard.press(KEY_ESC);
  80. Keyboard.release(KEY_ESC);
  81. }
  82. if (MX06.fallingEdge()) {
  83. Keyboard.press(KEY_RIGHT);
  84. Keyboard.release(KEY_RIGHT);
  85. }
  86. if (MX07.fallingEdge()) {
  87. Keyboard.press(KEY_END);
  88. Keyboard.release(KEY_END);
  89. }
  90. if (MX08.fallingEdge()) {
  91. Keyboard.press(KEY_DOWN);
  92. Keyboard.release(KEY_DOWN);
  93. }
  94. if (MX09.fallingEdge()) {
  95. Keyboard.press(KEY_PAGE_DOWN);
  96. Keyboard.release(KEY_PAGE_DOWN);
  97. }
  98. if (MX10.fallingEdge()) {
  99. Keyboard.press(KEY_BACKSPACE);
  100. Keyboard.release(KEY_BACKSPACE);
  101. }
  102. if (MX11.fallingEdge()) {
  103. Keyboard.press(KEY_SPACE);
  104. Keyboard.release(KEY_SPACE);
  105. }
  106. if (MX12.fallingEdge()) {
  107. Keyboard.press(KEY_ENTER);
  108. Keyboard.release(KEY_ENTER);
  109. }
  110. }