8
pinMode
(
TxD
,
OUTPUT
);
setupBleConnection
();
}
void
loop
()
{
char
recvChar
;
while
(
1
){
if
(
BLE
.
available
()){
//check if there's any data sent from the
remote BLE
recvChar
=
BLE
.
read
();
Serial
.
(
recvChar
);
}
if
(
Serial
.
available
()){
//check if there's any data sent from the
local serial terminal, you can add the other applications here
recvChar
=
Serial
.
read
();
BLE
.
(
recvChar
);
}
}
}
void
setupBleConnection
()
{
BLE
.
begin
(
9600
);
//Set BLE BaudRate to default baud rate 9600
BLE
.
(
"AT+CLEAR"
);
//clear all previous setting
BLE
.
(
"AT+ROLE0"
);
//set the bluetooth name as a slaver
BLE
.
(
"AT+SAVE1"
);
//don't save the connect information
}
4.2
Demo : BLE Master
#include <SoftwareSerial.h>
//Software Serial Port
#define RxD 2
#define TxD 3
#define DEBUG_ENABLED 1
SoftwareSerial BLE
(
RxD
,
TxD
);
void
setup
()
{
Serial
.
begin
(
9600
);