Advertisement
j0h

blowHard.ino

j0h
Mar 15th, 2025
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Keyboard.h>
  2. #include <Bounce2.h>
  3.  
  4. #define left_mic 0
  5. #define rght_mic 1
  6. #define fwd_mic  2
  7.  
  8. // Create Bounce objects for buttons
  9. Bounce left = Bounce();
  10. Bounce rght = Bounce();
  11. Bounce fwd = Bounce();
  12.  
  13. void setup() {
  14.  
  15.   Serial.begin(19200);
  16.  // delay(3000);
  17. pinMode(0, INPUT_PULLUP);
  18. pinMode(1, INPUT_PULLUP);
  19. pinMode(2, INPUT_PULLUP);
  20.  
  21.  int bounceTime = 1;
  22.   // Attach buttons to Bounce objects and set debounce interval
  23.   left.attach(left_mic, INPUT_PULLUP);
  24.   left.interval(bounceTime);
  25.  
  26.   rght.attach(rght_mic, INPUT_PULLUP);
  27.   rght.interval(bounceTime);
  28.  
  29.   fwd.attach(fwd_mic, INPUT_PULLUP);
  30.   fwd.interval(bounceTime);
  31. Keyboard.begin();
  32. }
  33.  
  34. void loop() {
  35.   left.update();
  36.   rght.update();
  37.   fwd.update();
  38.  
  39.   // Handle button presses with debouncing
  40.   if (left.fell()) {
  41.     Serial.println("LEFT");
  42.     Keyboard.press(KEY_LEFT);
  43.     Keyboard.release(KEY_LEFT);
  44.   }
  45.   if (rght.fell()) {
  46.     Serial.println("Riiight");
  47.     Keyboard.press(KEY_RIGHT);
  48.     Keyboard.release(KEY_RIGHT);
  49.   }
  50.   if (fwd.fell()) {
  51.     Serial.println("Forward!");
  52.     Keyboard.press(KEY_UP_ARROW);
  53.     Keyboard.release(KEY_UP_ARROW);
  54.  
  55.   }  
  56.  
  57. }
  58. /*
  59.  
  60.  
  61.   RFWD.update();
  62.   LFWD.update();
  63.   rota.update();
  64.   rset.update();
  65.   zmin.update();
  66.   zout.update();
  67.   zmax.update();
  68.   lrota.update();
  69.  
  70.  
  71.   if (RFWD.fell()) {
  72.     Keyboard.press(KEY_LEFT_SHIFT);
  73.     Keyboard.press(KEY_R);
  74.     Keyboard.press(KEY_UP_ARROW);
  75.     Keyboard.release(KEY_R);
  76.     Keyboard.release(KEY_UP_ARROW);
  77.     Keyboard.release(KEY_LEFT_SHIFT);
  78.   }
  79.   if (LFWD.fell()) {
  80.     Keyboard.press(KEY_UP_ARROW);
  81.     Keyboard.press(KEY_R);
  82.     Keyboard.release(KEY_UP_ARROW);
  83.     Keyboard.release(KEY_R);
  84.   }
  85.   if (rota.fell()) {
  86.     Keyboard.press(KEY_R);
  87.     Keyboard.release(KEY_R);
  88.   }
  89.   if (rset.fell()) {
  90.     Keyboard.press(KEY_X);
  91.     Keyboard.release(KEY_X);
  92.   }
  93.   if (zmin.fell()) {
  94.     Keyboard.press(KEYPAD_MINUS);
  95.     Keyboard.release(KEYPAD_MINUS);
  96.   }
  97.   if (zmax.fell()) {
  98.     Keyboard.press(KEYPAD_PLUS);
  99.     Keyboard.release(KEYPAD_PLUS);
  100.   }
  101.   if (lrota.fell()) {
  102.     Keyboard.press(KEY_R);
  103.     Keyboard.release(KEY_R);
  104.   }
  105. */
  106.  
  107.  
  108.  
  109.   /*
  110.   const int debounceInterval = 5;
  111.  
  112.   // Attach buttons to Bounce objects and set debounce interval
  113.   left.attach(aleft, INPUT_PULLUP);
  114.   left.interval(debounceInterval);
  115.  
  116.   rght.attach(arght, INPUT_PULLUP);
  117.   rght.interval(debounceInterval);
  118.  
  119.   fwd.attach(afwd, INPUT_PULLUP);
  120.   fwd.interval(debounceInterval);
  121.  
  122.   RFWD.attach(aRFWD, INPUT_PULLUP);
  123.   RFWD.interval(debounceInterval);
  124.  
  125.   LFWD.attach(aLFWD, INPUT_PULLUP);
  126.   LFWD.interval(debounceInterval);
  127.  
  128.   rota.attach(arota, INPUT_PULLUP);
  129.   rota.interval(debounceInterval);
  130.  
  131.   rset.attach(arset, INPUT_PULLUP);
  132.   rset.interval(debounceInterval);
  133.  
  134.   zmin.attach(azmin, INPUT_PULLUP);
  135.   zmin.interval(debounceInterval);
  136.  
  137.   zout.attach(azout, INPUT_PULLUP);
  138.   zout.interval(debounceInterval);
  139.  
  140.   zmax.attach(azmax, INPUT_PULLUP);
  141.   zmax.interval(debounceInterval);
  142.  
  143.   lrota.attach(alrota, INPUT_PULLUP);
  144.   lrota.interval(debounceInterval);
  145. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement