SHARE
TWEET

Rewritten keyboard code

grassytrainer Oct 25th, 2019 (edited) 197 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <keyboard.h>
  2. #include <Bounce.h>
  3.  
  4. //LED light
  5. int led = 11;
  6.  
  7. Bounce button0 = Bounce(0, 10);
  8. Bounce button1 = Bounce(5, 10);  // 10 = 10 ms debounce time
  9. Bounce button2 = Bounce(9, 10);  // which is appropriate for
  10. Bounce button3 = Bounce(10, 10);  // most mechanical pushbuttons
  11.  
  12. void setup(){
  13.   //Here's my current setup.
  14.  
  15.   pinMode(0, INPUT_PULLUP);
  16.   pinMode(5, INPUT_PULLUP);
  17.   pinMode(9, INPUT_PULLUP);
  18.   pinMode(10, INPUT_PULLUP);
  19. }
  20.  
  21. void loop(){
  22.  
  23.   //this is the led light control so i know the board is working.
  24.   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  25.  
  26.   button0.update();
  27.   button1.update();
  28.   button2.update();
  29.   button3.update();
  30.  
  31. // Undo
  32.   if (button0.fallingEdge()) {
  33.     Keyboard.press(MODIFIERKEY_CTRL);
  34.     Keyboard.press(KEY_Z);
  35.   }
  36.   if (button0.risingEdge()) {
  37.     Keyboard.release(MODIFIERKEY_CTRL);
  38.     Keyboard.release(KEY_Z);
  39.   }
  40.  
  41.  // Brush [B]
  42.    if (button1.fallingEdge()) {
  43.     Keyboard.press(KEY_B);
  44.   }
  45.   if (button1.risingEdge()) {
  46.     Keyboard.release(KEY_B);
  47.   }
  48.  
  49.   // Hand Tool
  50.   if (button2.fallingEdge()) {
  51.     Keyboard.press(KEY_SPACE);
  52.   }
  53.   if (button2.risingEdge()) {
  54.     Keyboard.release(KEY_SPACE);
  55.   }
  56.   // Save As...
  57.   if (button3.fallingEdge()) {
  58.     Keyboard.press(MODIFIERKEY_CTRL | MODIFIERKEY_SHIFT);
  59.     Keyboard.press(KEY_S);
  60.   }
  61.   if (button3.risingEdge()) {
  62.     Keyboard.release(MODIFIERKEY_CTRL | MODIFIERKEY_SHIFT);
  63.     Keyboard.release(KEY_S);
  64.   }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top