Created
December 5, 2020 03:58
-
-
Save buildcircuit/85c429b486e64be9fdc7029a2ca843cd to your computer and use it in GitHub Desktop.
Bluetooth-Arduino module from BuildCircuit
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
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