Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sketch for Arduino Bluetooth Controller
void setup() {
// initialize serial communication:
Serial.begin(38400);// this can be different for your Bluetooth module. It can be 9600 also.
// initialize the LED pins:
for (int thisPin = 2; thisPin < 13; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// read the sensor:
if (Serial.available() > 0) {
int inByte = Serial.read();
switch (inByte) {
case 'A':// when the app sends A, it turns on D13
digitalWrite(13, HIGH);
break;
case 'B':// when the app sends B, it turns off D13
digitalWrite(13, LOW);
break;
case 'C':// when the app sends A, it turns on D13
digitalWrite(12, HIGH);
break;
case 'D':// when the app sends B, it turns off D13
digitalWrite(12, LOW);
break;
case 'E':// when the app sends A, it turns on D13
digitalWrite(11, HIGH);
break;
case 'F':// when the app sends B, it turns off D13
digitalWrite(11, LOW);
break;
case 'G':// when the app sends A, it turns on D13
digitalWrite(10, HIGH);
break;
case 'H':// when the app sends B, it turns off D13
digitalWrite(10, LOW);
break;
case 'I':// when the app sends A, it turns on D13
digitalWrite(9, HIGH);
break;
case 'J':// when the app sends B, it turns off D13
digitalWrite(9, LOW);
break;
case 'K':// when the app sends A, it turns on D13
digitalWrite(8, HIGH);
break;
case 'L':// when the app sends B, it turns off D13
digitalWrite(8, LOW);
break;
case 'M':// when the app sends A, it turns on D13
digitalWrite(7, HIGH);
break;
case 'N':// when the app sends B, it turns off D13
digitalWrite(7, LOW);
break;
case 'O':// when the app sends A, it turns on D13
digitalWrite(6, HIGH);
break;
case 'P':// when the app sends B, it turns off D13
digitalWrite(6, LOW);
break;
case 'Q':// when the app sends A, it turns on D13
digitalWrite(5, HIGH);
break;
case 'R':// when the app sends B, it turns off D13
digitalWrite(5, LOW);
break;
case 'S':// when the app sends A, it turns on D13
digitalWrite(4, HIGH);
break;
case 'T':// when the app sends B, it turns off D13
digitalWrite(4, LOW);
break;
case 'U':// when the app sends A, it turns on D13
digitalWrite(3, HIGH);
break;
case 'V':// when the app sends B, it turns off D13
digitalWrite(3, LOW);
break;
case 'W':// when the app sends A, it turns on D13
digitalWrite(2, HIGH);
break;
case 'X':// when the app sends B, it turns off D13
digitalWrite(2, LOW);
break;
default:
// turn all the LEDs off:
for (int thisPin = 2; thisPin < 13; thisPin++) {
digitalWrite(thisPin, LOW);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment