bitelaserkhalif555

Arduino stream deck for price of "next to nothing"

Aug 22nd, 2021 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. uint8_t buf[8] = {
  2.   0
  3. };  // Keyboard Report Buffer: 8 bytes
  4.  
  5. #define B1 12
  6. #define B2 11
  7. #define B3 10
  8. #define B4 9
  9. #define B5 8
  10. #define B6 7
  11.  
  12. //#define SERIAL_DEBUG  // for serial debug: remove //
  13.                         // for actual HID: put //
  14. int state = 1;
  15.  
  16. void setup()
  17. {
  18.   Serial.begin(9600);
  19.   pinMode(B1, INPUT);
  20.   pinMode(B2, INPUT);
  21.   pinMode(B3, INPUT);
  22.   pinMode(B4, INPUT);
  23.   pinMode(B5, INPUT);
  24.   pinMode(B6, INPUT);
  25.   // enable internal pull-ups
  26.   digitalWrite(B1, 1);
  27.   digitalWrite(B2, 1);
  28.   digitalWrite(B3, 1);
  29.   digitalWrite(B4, 1);
  30.   digitalWrite(B5, 1);
  31.   digitalWrite(B6, 1);
  32.  
  33.   delay(200);
  34. }
  35. //we are using hex 0xseries
  36. void loop()
  37. {
  38.   state = digitalRead(B1);
  39.   if (state != 1) {
  40.     buf[2] = 0x68;    // f13 or 104
  41.     Serial.write(buf, 8); // Send keypress
  42.     releaseKey();
  43.   }
  44.  
  45.   state = digitalRead(B2);
  46.   if (state != 1) {
  47.     buf[2] = 0x69;   // f14 or 105
  48.     Serial.write(buf, 8); // Send keypress
  49.     releaseKey();
  50.   }
  51.  
  52.   state = digitalRead(B3);
  53.   if (state != 1) {
  54.     buf[2] = 0x6A;   // f15 key or 106
  55.     Serial.write(buf, 8); // Send keypress
  56.     releaseKey();
  57.   }
  58.  
  59.     state = digitalRead(B4);
  60.   if (state != 1) {
  61.     buf[2] = 0x6B;    // f16 key or 107
  62.     Serial.write(buf, 8); // Send keypress
  63.     releaseKey();
  64.   }
  65.  
  66.   state = digitalRead(B5);
  67.   if (state != 1) {
  68.     buf[2] = 0x6C;   // f17 key or 108
  69.     Serial.write(buf, 8); // Send keypress
  70.     releaseKey();
  71.   }
  72.  
  73.   state = digitalRead(B6);
  74.   if (state != 1) {
  75.     buf[2] = 0x6D;   // f18 key or 109
  76.     Serial.write(buf, 8); // Send keypress
  77.     releaseKey();
  78.   }
  79. }
  80.  
  81. void releaseKey()
  82. {
  83.   delay(200);
  84.   buf[0] = 0;
  85.   buf[2] = 0;
  86.   Serial.write(buf, 8); // Release key  
  87. }
Add Comment
Please, Sign In to add comment