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.

arduino-example.ino 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "HID-Project.h"
  2. #include <AStar32U4.h>
  3. //debounce milliseconds
  4. const int debounce = 10;
  5. //Switch Pins
  6. const byte k[4] = { 9, 8, 7, 6 };
  7. //Switch status
  8. boolean s[4] = { 0, 0, 0, 0 };
  9. //M for Media Key, K for Keyboard
  10. const char codetype[4] = { 'K', 'K', 'K', 'K' };
  11. //Keycodes
  12. const ConsumerKeycode ccode[4] = { MEDIA_VOLUME_MUTE,
  13. MEDIA_PLAY_PAUSE,
  14. MEDIA_PLAY_PAUSE,
  15. MEDIA_PLAY_PAUSE
  16. };
  17. const KeyboardKeycode kcode[4] = { KEY_LEFT_ARROW,
  18. KEY_DOWN_ARROW,
  19. KEY_UP_ARROW,
  20. KEY_RIGHT_ARROW
  21. };
  22. void setup() {
  23. Keyboard.begin();
  24. Consumer.begin();
  25. //setup inputs, turn on pullups
  26. for (int i = 0; i <= 3; i++) {
  27. pinMode(k[i], INPUT);
  28. digitalWrite(k[i], 1);
  29. pinMode(13, OUTPUT);
  30. digitalWrite(13, 1);
  31. }
  32. }
  33. void loop() {
  34. CheckKeys();
  35. delay(debounce);
  36. }
  37. void CheckKeys() {
  38. for (int i = 0; i <= 3; i++) {
  39. if (codetype[i] == 'M') {
  40. if (digitalRead(k[i]) == 0) {
  41. if (s[i] == 0) {
  42. Consumer.press((ccode[i]));
  43. s[i] = 1;
  44. }
  45. }
  46. else {
  47. if (s[i] == 1) {
  48. s[i] = 0;
  49. Consumer.release((ccode[i]));
  50. }
  51. }
  52. }
  53. if (codetype[i] == 'K') {
  54. if (digitalRead(k[i]) == 0) {
  55. if (s[i] == 0) {
  56. Keyboard.press((kcode[i]));
  57. s[i] = 1;
  58. }
  59. }
  60. else {
  61. if (s[i] == 1) {
  62. s[i] = 0;
  63. Keyboard.release((kcode[i]));
  64. }
  65. }
  66. }
  67. }
  68. }