Bluetooth serial communication with Bluetooth Shield from Seeed Studio

Dependencies:   BluetoothSerial mbed

Fork of Bluetooth_demo by Yihui Xiong

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 
00003 #include "mbed.h"
00004 #include "BluetoothSerial.h"
00005 
00006 DigitalOut led1(LED1);
00007 DigitalOut led2(LED2);
00008 BluetoothSerial bluetooth(P0_19, P0_18);
00009 
00010 int main()
00011 { 
00012     int count = 0;
00013 
00014     bluetooth.setup();
00015 #if 1
00016     bluetooth.slave("btslave8seeed");  // default PIN code: 0000
00017     wait(2);
00018     bluetooth.connect();
00019 #else
00020     bluetooth.master("btmaster8seeed");
00021     wait(2);
00022     bluetooth.connect("btslave8seeed");
00023 #endif
00024    
00025     while (1) {
00026         if (bluetooth.readable()) {
00027             led2 = !led2;
00028         }
00029         
00030         count++;
00031         if (count >= 1000000) {
00032             led1 = !led1;
00033             count = 0;
00034         }
00035     }
00036     
00037 }
00038