Created
December 9, 2020 00:16
-
-
Save buildcircuit/a56ecb009cc959697e6446297394bba2 to your computer and use it in GitHub Desktop.
Bluetooth experiment2
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(); | |
switch (inByte) { | |
case 'A':// when the app sends A | |
digitalWrite(2, HIGH); | |
delay(1000); | |
digitalWrite(2, LOW); | |
break; | |
case 'B':// when the app sends B | |
digitalWrite(4, HIGH); | |
delay(1000); | |
digitalWrite(4, LOW); | |
break; | |
case 'C':// when the app sends C | |
digitalWrite(6, HIGH); | |
delay(1000); | |
digitalWrite(6, LOW); | |
break; | |
case 'D':// when the app sends D | |
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