Skip to content

Instantly share code, notes, and snippets.

@farizdotid
Created January 24, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farizdotid/1f69d823a76fbcd94a06a3c8300676eb to your computer and use it in GitHub Desktop.
Save farizdotid/1f69d823a76fbcd94a06a3c8300676eb to your computer and use it in GitHub Desktop.
#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