Created
January 24, 2018 14:29
-
-
Save farizdotid/1f69d823a76fbcd94a06a3c8300676eb to your computer and use it in GitHub Desktop.
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> | |
#include <stdio.h> | |
int ledONE = 13; | |
int bluetoothTX = 1 ; | |
int bluetoothRX = 0 ; | |
char receivedValue ; | |
SoftwareSerial bluetooth ( bluetoothTX, bluetoothRX ); | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println("console> "); | |
pinMode(ledONE, OUTPUT); | |
bluetooth.begin(115200); | |
bluetooth.print("$$$"); | |
delay(100); | |
bluetooth.println("U,9600,N"); | |
bluetooth.begin(9600); | |
} | |
void loop() | |
{ | |
int data = 0; | |
if( bluetooth.available() ) | |
{ | |
data = (int) bluetooth.read(); | |
Serial.println(data); // for debugging, show received data | |
if(data == 26) | |
{ | |
allDown() ; | |
}else if(data == 89){ | |
allUp() ; | |
} | |
bluetooth.flush(); // IMPORTANT clean bluetooth stream, flush stuck data | |
} | |
} | |
// SHUT DOWN all leds | |
void allDown() | |
{ | |
digitalWrite(ledONE, LOW ) ; | |
} | |
// ALL up now :) | |
void allUp() | |
{ | |
digitalWrite(ledONE, HIGH) ; | |
} | |
void setLEDone(int brighteness) | |
{ | |
analogWrite(ledONE, brighteness ) ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment