Bluetooth serial communication with Bluetooth Shield from Seeed Studio

Dependencies:   BluetoothSerial mbed

Fork of Bluetooth_demo by Yihui Xiong

Committer:
yihui
Date:
Thu Feb 20 03:31:49 2014 +0000
Revision:
0:e0f48c28e5c1
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:e0f48c28e5c1 1
yihui 0:e0f48c28e5c1 2
yihui 0:e0f48c28e5c1 3 #include "mbed.h"
yihui 0:e0f48c28e5c1 4 #include "BluetoothSerial.h"
yihui 0:e0f48c28e5c1 5
yihui 0:e0f48c28e5c1 6 DigitalOut led1(LED1);
yihui 0:e0f48c28e5c1 7 DigitalOut led2(LED2);
yihui 0:e0f48c28e5c1 8 BluetoothSerial bluetooth(P0_19, P0_18);
yihui 0:e0f48c28e5c1 9
yihui 0:e0f48c28e5c1 10 int main()
yihui 0:e0f48c28e5c1 11 {
yihui 0:e0f48c28e5c1 12 int count = 0;
yihui 0:e0f48c28e5c1 13
yihui 0:e0f48c28e5c1 14 bluetooth.setup();
yihui 0:e0f48c28e5c1 15 #if 1
yihui 0:e0f48c28e5c1 16 bluetooth.slave("btslave8seeed"); // default PIN code: 0000
yihui 0:e0f48c28e5c1 17 wait(2);
yihui 0:e0f48c28e5c1 18 bluetooth.connect();
yihui 0:e0f48c28e5c1 19 #else
yihui 0:e0f48c28e5c1 20 bluetooth.master("btmaster8seeed");
yihui 0:e0f48c28e5c1 21 wait(2);
yihui 0:e0f48c28e5c1 22 bluetooth.connect("btslave8seeed");
yihui 0:e0f48c28e5c1 23 #endif
yihui 0:e0f48c28e5c1 24
yihui 0:e0f48c28e5c1 25 while (1) {
yihui 0:e0f48c28e5c1 26 if (bluetooth.readable()) {
yihui 0:e0f48c28e5c1 27 led2 = !led2;
yihui 0:e0f48c28e5c1 28 }
yihui 0:e0f48c28e5c1 29
yihui 0:e0f48c28e5c1 30 count++;
yihui 0:e0f48c28e5c1 31 if (count >= 1000000) {
yihui 0:e0f48c28e5c1 32 led1 = !led1;
yihui 0:e0f48c28e5c1 33 count = 0;
yihui 0:e0f48c28e5c1 34 }
yihui 0:e0f48c28e5c1 35 }
yihui 0:e0f48c28e5c1 36
yihui 0:e0f48c28e5c1 37 }
yihui 0:e0f48c28e5c1 38