Created
August 18, 2012 00:54
-
-
Save Lauszus/3383715 to your computer and use it in GitHub Desktop.
Help for Ron tay (http://www.circuitsathome.com/mcu/bluetooth-rfcommspp-service-support-for-usb-host-2-0-library-released/comment-page-1#comment-13703)
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
#include <SPP.h> | |
USB Usb; | |
BTD Btd(&Usb); | |
SPP SerialBT(&Btd); | |
char val[3]; | |
int pin1 = 22; | |
int pin2 = 24; | |
int pin3 = 26; | |
int pin4 = 28; | |
int pin5 = 30; | |
int pin6 = 32; | |
int index = 0; | |
void setup() { | |
pinMode(pin1, OUTPUT); | |
pinMode(pin2, OUTPUT); | |
pinMode(pin3, OUTPUT); | |
pinMode(pin4, OUTPUT); | |
pinMode(pin5, OUTPUT); | |
pinMode(pin6, OUTPUT); | |
Serial.begin(9600); // This is only used to print debuggin from the BTD and SPP library | |
if (Usb.Init() == -1) { | |
Serial.print(F("\r\nOSC did not start")); | |
while(1); //halt | |
} | |
} | |
void loop() { | |
Usb.Task(); | |
if(SerialBT.connected) { | |
if(SerialBT.available()){ | |
if(index < 3){ | |
val[index] = SerialBT.read(); | |
SerialBT.print(val[index]); // Print character back to connected device | |
index++; | |
} | |
if(index == 3){ | |
SerialBT.println(); | |
Serial.println(val); // For debugging | |
if(strncmp("p11", val, 3) == 0) | |
digitalWrite(pin1, HIGH); | |
else if(strncmp("p10", val, 3) == 0) | |
digitalWrite(pin1, LOW); | |
else if(strncmp("p21", val, 3) == 0) | |
digitalWrite(pin2, HIGH); | |
else if(strncmp("p20", val, 3) == 0) | |
digitalWrite(pin2, LOW); | |
else if(strncmp("p31", val, 3) == 0) | |
digitalWrite(pin3, HIGH); | |
else if(strncmp("p30", val, 3) == 0) | |
digitalWrite(pin3, LOW); | |
else if(strncmp("p41", val, 3) == 0) | |
digitalWrite(pin4, HIGH); | |
else if(strncmp("p40", val, 3) == 0) | |
digitalWrite(pin4, LOW); | |
else if(strncmp("p51", val, 3) == 0) | |
digitalWrite(pin5, HIGH); | |
else if(strncmp("p50", val, 3) == 0) | |
digitalWrite(pin5, LOW); | |
else if(strncmp("p61", val, 3) == 0) | |
digitalWrite(pin6, HIGH); | |
else if(strncmp("p60", val, 3) == 0) | |
digitalWrite(pin6, LOW); | |
else if(strncmp("ar1", val, 3) == 0) { | |
digitalWrite(pin1, HIGH); | |
digitalWrite(pin2, HIGH); | |
digitalWrite(pin3, HIGH); | |
} | |
else if(strncmp("ar0", val, 3) == 0) { | |
digitalWrite(pin1, LOW); | |
digitalWrite(pin2, LOW); | |
digitalWrite(pin3, LOW); | |
} | |
else if(strncmp("ag1", val, 3) == 0) { | |
digitalWrite(pin4, HIGH); | |
digitalWrite(pin5, HIGH); | |
digitalWrite(pin6, HIGH); | |
} | |
else if(strncmp("ag0", val, 3) == 0) { | |
digitalWrite(pin4, LOW); | |
digitalWrite(pin5, LOW); | |
digitalWrite(pin6, LOW); | |
} | |
index = 0; | |
} | |
} | |
} | |
else | |
index = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment