![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Simple program for the Bluetooth module by Seeed.
main.cpp@0:0d3565827d63, 2014-08-13 (annotated)
- Committer:
- damarisochoa
- Date:
- Wed Aug 13 22:42:05 2014 +0000
- Revision:
- 0:0d3565827d63
This is a basic program for FRDM-KL25Z using the Bluetooth module by Seeed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
damarisochoa | 0:0d3565827d63 | 1 | #include "mbed.h" |
damarisochoa | 0:0d3565827d63 | 2 | |
damarisochoa | 0:0d3565827d63 | 3 | Serial bts (USBTX, USBRX); |
damarisochoa | 0:0d3565827d63 | 4 | Serial pc (USBTX, USBRX); |
damarisochoa | 0:0d3565827d63 | 5 | DigitalOut myled(LED1); |
damarisochoa | 0:0d3565827d63 | 6 | |
damarisochoa | 0:0d3565827d63 | 7 | void flushSerialBuffer() |
damarisochoa | 0:0d3565827d63 | 8 | { |
damarisochoa | 0:0d3565827d63 | 9 | char char1 = 0; |
damarisochoa | 0:0d3565827d63 | 10 | while (bts.readable()) { |
damarisochoa | 0:0d3565827d63 | 11 | char1 = bts.getc(); |
damarisochoa | 0:0d3565827d63 | 12 | } |
damarisochoa | 0:0d3565827d63 | 13 | return; |
damarisochoa | 0:0d3565827d63 | 14 | } |
damarisochoa | 0:0d3565827d63 | 15 | |
damarisochoa | 0:0d3565827d63 | 16 | |
damarisochoa | 0:0d3565827d63 | 17 | void ComBTSetup(){ |
damarisochoa | 0:0d3565827d63 | 18 | |
damarisochoa | 0:0d3565827d63 | 19 | pc.baud(38400); |
damarisochoa | 0:0d3565827d63 | 20 | |
damarisochoa | 0:0d3565827d63 | 21 | // Initialize Baud Rate for SEEED Bluetooth module |
damarisochoa | 0:0d3565827d63 | 22 | bts.baud(38400); |
damarisochoa | 0:0d3565827d63 | 23 | |
damarisochoa | 0:0d3565827d63 | 24 | // Bluetooth module initialzation |
damarisochoa | 0:0d3565827d63 | 25 | // Adapted from Arduino sample code provided on SEEED's webpage |
damarisochoa | 0:0d3565827d63 | 26 | bts.printf("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode. STDWWMOD=1 server mode |
damarisochoa | 0:0d3565827d63 | 27 | |
damarisochoa | 0:0d3565827d63 | 28 | bts.printf("\r\n+STNA=Freescale Robot\r\n"); //set the bluetooth name as "Freescale Robot" |
damarisochoa | 0:0d3565827d63 | 29 | |
damarisochoa | 0:0d3565827d63 | 30 | bts.printf("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me |
damarisochoa | 0:0d3565827d63 | 31 | |
damarisochoa | 0:0d3565827d63 | 32 | bts.printf("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here |
damarisochoa | 0:0d3565827d63 | 33 | wait(2); // This delay is required. |
damarisochoa | 0:0d3565827d63 | 34 | bts.printf("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable |
damarisochoa | 0:0d3565827d63 | 35 | pc.printf("The slave bluetooth is inquirable!"); |
damarisochoa | 0:0d3565827d63 | 36 | wait(2); // This delay is required. |
damarisochoa | 0:0d3565827d63 | 37 | flushSerialBuffer(); |
damarisochoa | 0:0d3565827d63 | 38 | wait(2); // This delay is required. |
damarisochoa | 0:0d3565827d63 | 39 | } |
damarisochoa | 0:0d3565827d63 | 40 | |
damarisochoa | 0:0d3565827d63 | 41 | |
damarisochoa | 0:0d3565827d63 | 42 | int main() { |
damarisochoa | 0:0d3565827d63 | 43 | |
damarisochoa | 0:0d3565827d63 | 44 | |
damarisochoa | 0:0d3565827d63 | 45 | ComBTSetup(); |
damarisochoa | 0:0d3565827d63 | 46 | char temp=0; |
damarisochoa | 0:0d3565827d63 | 47 | while(1) { |
damarisochoa | 0:0d3565827d63 | 48 | temp=bts.getc(); |
damarisochoa | 0:0d3565827d63 | 49 | pc.printf("%d",temp); |
damarisochoa | 0:0d3565827d63 | 50 | // the variable temp will have what is received via bluetooth |
damarisochoa | 0:0d3565827d63 | 51 | myled = 1; |
damarisochoa | 0:0d3565827d63 | 52 | wait(1); |
damarisochoa | 0:0d3565827d63 | 53 | myled = 0; |
damarisochoa | 0:0d3565827d63 | 54 | |
damarisochoa | 0:0d3565827d63 | 55 | } |
damarisochoa | 0:0d3565827d63 | 56 | } |