Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bluetooth-Arduino module from BuildCircuit
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();
// do something different depending on the character received.
// The switch statement expects single number values for each case; in this
// example, though, you're using single quotes to tell the controller to get
// the ASCII value for the character. For example 'a' = 97, 'b' = 98,
// and so forth:
switch (inByte) {
case '1':// when the app sends 1
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
break;
case '2':// when the app sends 2
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(4, LOW);
break;
case '3':// when the app sends 3
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(6, LOW);
break;
case '4':// when the app sends 4
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
break;
//likewise, you can find an app that can send digits from 1 to 12.
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