Skip to content

Instantly share code, notes, and snippets.

@cpl
Last active May 30, 2019 13:44
Show Gist options
  • Save cpl/610b6ca3ec9c20cdceb2eecbde51b076 to your computer and use it in GitHub Desktop.
Save cpl/610b6ca3ec9c20cdceb2eecbde51b076 to your computer and use it in GitHub Desktop.
Arduino Bluetooth
#define TX 1
#define RX 0
#define LED 7
#define BUFFER_SIZE 16
char bufr[BUFFER_SIZE];
void setup(){
Serial.begin(9600);
pinMode(TX, OUTPUT);
pinMode(RX, INPUT);
pinMode(LED, OUTPUT);
}
void loop(){
int i=0;
delay(500);
if (Serial.available() > 0) {
while (Serial.available() > 0) {
bufr[i++] = Serial.read();
}
bufr[i]='\0';
if(bufr[0] == '0') {
digitalWrite(LED, LOW);
} else if (bufr[0] == '1') {
digitalWrite(LED, HIGH);
}
Serial.println(bufr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment