#include "BluetoothSerial.h"
// Create an instance of the BluetoothSerial class
BluetoothSerial BTSerial;
void setup() {
//led
pinMode(2, OUTPUT);
// Initialize the Serial Monitor
Serial.begin(115200);
// Initialize Bluetooth with a device name
BTSerial.begin("RC YF CAR");
for(int i=0; i<5; i++)
{
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
delay(1000);
}
Serial.print("BT Open");
}
void loop() {
// Check if there is any data available on the Bluetooth serial connection
if (BTSerial.available()) {
// Read the data from Bluetooth serial
char incomingChar = BTSerial.read();
// Print the received data to the Serial Monitor
Serial.print("Received via BT: ");
Serial.println(incomingChar);
if(incomingChar == '1')
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
}
}