Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Crhistian Lucumi
- */
- /****************************************************************************************************************/
- /* BluetoothKeyboard - Control the keyboard across a bluetooth connection */
- /****************************************************************************************************************/
- #include <SoftSerial_INT0.h> //https://github.com/J-Rios/Digispark_SoftSerial-INT0
- #include "DigiKeyboard.h"
- #define P_RX 2 // Reception PIN (SoftSerial)
- #define P_TX 1 // Transmition PIN (SoftSerial)
- #define BLE_TIMEOUT 10000 // Time for connect with the BLE module
- #define KEY_ENTER 40 // Keyboard usage values (ENTER Key)
- #define KEY_ESC 41 // Keyboard usage values (ESCAPE Key)
- SoftSerial BLE(P_RX, P_TX); // Software serial port for control the BLE module
- /****************************************************************************************************************/
- void setup()
- {
- BLE.begin(9600); // Initialize the serial port
- DigiKeyboard.delay(BLE_TIMEOUT); // Wait the module for connect
- }
- void loop()
- {
- static char cmd; // Get Command variable
- if(BLE.available()) // If there is any data incoming from the serial port
- {
- cmd = BLE.read(); // Get command
- // Manage the command received
- if(cmd == 'A')
- DigiKeyboard.sendKeyStroke(KEY_ARROW_LEFT);
- else if(cmd == 'B')
- DigiKeyboard.sendKeyStroke(KEY_ENTER);
- else if(cmd == 'C')
- DigiKeyboard.sendKeyStroke(KEY_F5);
- else if(cmd == 'D')
- DigiKeyboard.sendKeyStroke(KEY_ESC);
- // ...
- }
- DigiKeyboard.update(); // Update the USB connection (maintain alive the connection)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement