Created
February 3, 2018 13:24
-
-
Save sergio1990/95f8d47eda4222e83577b6a50a67e6c4 to your computer and use it in GitHub Desktop.
Control LED via the Bluetooth channel using Arduino+HM-10 BLE board
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
#include <SoftwareSerial.h> | |
#define ledPin 7 | |
SoftwareSerial mySerial(2, 3); | |
int val; | |
void setup() { | |
pinMode(ledPin, OUTPUT); | |
digitalWrite(ledPin, HIGH); | |
Serial.begin(9600); | |
mySerial.begin(9600); | |
} | |
void loop() { | |
if(mySerial.available() > 0){ | |
val = mySerial.read(); | |
Serial.print("Received: "); | |
Serial.println(val); | |
if (val == 0) { | |
digitalWrite(ledPin, LOW); | |
Serial.println("LED: OFF"); | |
} | |
else if (val == 1) { | |
digitalWrite(ledPin, HIGH); | |
Serial.println("LED: ON"); | |
} | |
} | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment