Skip to content

Instantly share code, notes, and snippets.

@Lauszus Lauszus/gist:3383715
Created Aug 18, 2012

Embed
What would you like to do?
#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
You can’t perform that action at this time.