Advertisement
CrhisDLM

Untitled

Jun 15th, 2018
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. /*
  2.  * Crhistian Lucumi
  3. */
  4.  
  5. /****************************************************************************************************************/
  6. /* BluetoothKeyboard - Control the keyboard across a bluetooth connection                                       */
  7. /****************************************************************************************************************/
  8.  
  9. #include <SoftSerial_INT0.h> //https://github.com/J-Rios/Digispark_SoftSerial-INT0
  10. #include "DigiKeyboard.h"
  11.  
  12. #define P_RX 2                        // Reception PIN (SoftSerial)
  13. #define P_TX 1                        // Transmition PIN (SoftSerial)
  14. #define BLE_TIMEOUT 10000             // Time for connect with the BLE module
  15. #define KEY_ENTER 40                  // Keyboard usage values (ENTER Key)
  16. #define KEY_ESC 41                    // Keyboard usage values (ESCAPE Key)
  17.  
  18. SoftSerial BLE(P_RX, P_TX);           // Software serial port for control the BLE module
  19.  
  20. /****************************************************************************************************************/
  21.  
  22. void setup()
  23. {
  24.     BLE.begin(9600); // Initialize the serial port    
  25.     DigiKeyboard.delay(BLE_TIMEOUT); // Wait the module for connect
  26. }
  27.  
  28. void loop()
  29. {
  30.     static char cmd; // Get Command variable
  31.    
  32.     if(BLE.available()) // If there is any data incoming from the serial port
  33.     {
  34.         cmd = BLE.read(); // Get command
  35.  
  36.         // Manage the command received
  37.         if(cmd == 'A')
  38.             DigiKeyboard.sendKeyStroke(KEY_ARROW_LEFT);
  39.         else if(cmd == 'B')
  40.             DigiKeyboard.sendKeyStroke(KEY_ENTER);
  41.         else if(cmd == 'C')
  42.             DigiKeyboard.sendKeyStroke(KEY_F5);
  43.         else if(cmd == 'D')
  44.             DigiKeyboard.sendKeyStroke(KEY_ESC);
  45.         // ...
  46.     }
  47.     DigiKeyboard.update(); // Update the USB connection (maintain alive the connection)
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement