Created
October 25, 2012 11:49
-
-
Save Crenshinibon/3952167 to your computer and use it in GitHub Desktop.
HID SPP switch sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TheTasTaTur - bt config | |
Author: | |
Dirk Porsche | |
Shiggy Enterprises UG (haftungsbeschränkt) | |
All Rights reserved | |
*/ | |
boolean hidMode = true; | |
void setup() { | |
pinMode(13,OUTPUT); | |
pinMode(10,INPUT); | |
digitalWrite(13,HIGH); | |
Serial.begin(115200); | |
} | |
void switchBTMode(){ | |
if(hidMode){ | |
enableBTCommandMode(); | |
Serial.write('S'); | |
Serial.write('~'); | |
Serial.write(','); | |
Serial.write('0'); | |
Serial.write('\r'); | |
Serial.flush(); | |
delay(200); | |
resetBT(); | |
digitalWrite(13,HIGH); | |
hidMode = false; | |
} | |
else { | |
enableBTCommandMode(); | |
Serial.write('S'); | |
Serial.write('~'); | |
Serial.write(','); | |
Serial.write('6'); | |
Serial.write('\r'); | |
Serial.flush(); | |
delay(200); | |
resetBT(); | |
digitalWrite(13,LOW); | |
hidMode = true; | |
} | |
} | |
void enableBTCommandMode(){ | |
Serial.write('$'); | |
Serial.write('$'); | |
Serial.write('$'); | |
Serial.flush(); | |
delay(200); | |
} | |
void enableBTDataMode(){ | |
Serial.write('-'); | |
Serial.write('-'); | |
Serial.write('-'); | |
Serial.flush(); | |
delay(200); | |
} | |
void connectBT(){ | |
enableBTCommandMode(); | |
Serial.write('I'); | |
Serial.write('N'); | |
Serial.write(','); | |
Serial.write('1'); | |
Serial.write('0'); | |
Serial.write(','); | |
Serial.write('0'); | |
Serial.write('0'); | |
Serial.write('0'); | |
Serial.write('0'); | |
Serial.write('0'); | |
Serial.write('1'); | |
Serial.write('\r'); | |
Serial.flush(); | |
delay(200); | |
Serial.write('C'); | |
Serial.write('F'); | |
Serial.write('I'); | |
Serial.write('\r'); | |
Serial.flush(); | |
delay(200); | |
} | |
void resetBT(){ | |
Serial.write('R'); | |
Serial.write(','); | |
Serial.write('1'); | |
Serial.write('\r'); | |
Serial.flush(); | |
delay(200); | |
} | |
long lastClickCounter = 0; | |
void loop() { | |
if(millis() - lastClickCounter > 1000){ | |
if(digitalRead(10) == HIGH){ | |
switchBTMode(); | |
lastClickCounter = millis(); | |
} | |
} | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment