#include //Software Serial Port
#define RxD 6
#define TxD 7
#define PINLED 9
#define LEDON() digitalWrite(PINLED, HIGH)
#define LEDOFF() digitalWrite(PINLED, LOW)
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(PINLED, OUTPUT);
LEDOFF();
setupBlueToothConnection();
}
void loop()
{
char recvChar;
while(1)
{
if(blueToothSerial.available())
{//check if there's any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar);
if(recvChar == '1')
{
LEDON();
}
else if(recvChar == '0')
{
LEDOFF();
}
}
}
}
void setupBlueToothConnection()
{
// Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.begin(38400);
// set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STWMOD=0\r\n");
// set the bluetooth name as "SeeedBTSlave"
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n");
// Permit Paired device to connect me
blueToothSerial.print("\r\n+STOAUT=1\r\n");
// Auto-connection should be forbidden here
blueToothSerial.print("\r\n+STAUTO=0\r\n");
delay(2000); // This delay is required.
// make the slave bluetooth inquirable
blueToothSerial.print("\r\n+INQ=1\r\n");
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
|