/*******************************************************************************/ // //Copyright (c) [2016] [Elliott Graham Magee] // //Permission is hereby granted, free of charge, to any person obtaining a copy //of this software and associated documentation files (the "Software"), to deal //in the Software without restriction, including without limitation the rights //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //copies of the Software, and to permit persons to whom the Software is //furnished to do so, subject to the following conditions: // //The above copyright notice and this permission notice shall be included in all //copies or substantial portions of the Software. // //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. // /*******************************************************************************/ #include #include #include "Adafruit_BLE.h" #include "Adafruit_BluefruitLE_SPI.h" #include "BluefruitConfig.h" #define FACTORYRESET_ENABLE 0 #define MINIMUM_FIRMWARE_VERSION "0.6.6" // Create the bluefruit object, as hardware serial Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST); void setup() { //if ( !ble.begin(VERBOSE_MODE) ) { ble.begin(VERBOSE_MODE); { } // Disable command echo from Bluefruit ble.echo(false); // Print Bluefruit information ble.info(); // Change the device name to make it easier to find if (! ble.sendCommandCheckOK(F( "AT+GAPDEVNAME=Bionic Clicker MKII" )) ) { } // Enable HID Service if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) ) { if ( !ble.sendCommandCheckOK(F( "AT+BleHIDEn=On" ))) { } } else { if (! ble.sendCommandCheckOK(F( "AT+BleKeyboardEn=On" ))) { } } } void loop() { int but1 = 0; //create an integer to save the state of button 1 int but2 = 0; //create an integer to save the state of button 2 int but3 = 0; //create an integer to save the state of button 3 pinMode(5, INPUT); //EMG overide pinMode(3, INPUT); //manual forward pinMode(2, INPUT); //manual backwards but1 = digitalRead(5); //reads status button 1 (EMG overide) but2 = digitalRead(3); //reads status button 2 (manual forward) but3 = digitalRead(2); //reads status button 3 (manual backwards) if (but1 == HIGH) // checks for EMG overide //manual overide off { int EMG = analogRead(A0); //reads current EMG values if (EMG > PLACE_YOUR_THRESHOLD_TRIGGER_VALUE_HERE) // EMG trigger threshold { ble.println("AT+BLEKEYBOARDCODE=00-00-4F-00-00-00-00"); //Right key press down ble.println("AT+BLEKEYBOARDCODE=00-00"); //keypress release delay(500); } else if (but2 == HIGH) //checks manual forward button { ble.println("AT+BLEKEYBOARDCODE=00-00-4F-00-00-00-00"); //Right key press down ble.println("AT+BLEKEYBOARDCODE=00-00"); //keypress release delay(500); } else if (but3 == HIGH) //checks manual back button { ble.println("AT+BLEKEYBOARDCODE=00-00-50-00-00-00-00"); //Left key press down ble.println("AT+BLEKEYBOARDCODE=00-00"); //keypress release delay(500); } } //manual overide on else if (but2 == HIGH) //checks manual forward button { ble.println("AT+BLEKEYBOARDCODE=00-00-4F-00-00-00-00"); //Right key press down ble.println("AT+BLEKEYBOARDCODE=00-00"); //keypress release delay(300); } else if (but3 == HIGH) //checks manual back button { ble.println("AT+BLEKEYBOARDCODE=00-00-50-00-00-00-00"); //Left key press down ble.println("AT+BLEKEYBOARDCODE=00-00"); //keypress release delay(300); } }