Bluetooth avanzado

Dependencies:   mbed

Committer:
gerardo_carmona
Date:
Tue Sep 23 21:03:10 2014 +0000
Revision:
0:1a819403fbb3
Bluetooth avanzado

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gerardo_carmona 0:1a819403fbb3 1 /*
gerardo_carmona 0:1a819403fbb3 2 -- TV_bluetooth-Rx-simple --
gerardo_carmona 0:1a819403fbb3 3 Example using a Bluetooth module. In this case
gerardo_carmona 0:1a819403fbb3 4 we use the HC-06 model.
gerardo_carmona 0:1a819403fbb3 5
gerardo_carmona 0:1a819403fbb3 6 Pairing code: 1234
gerardo_carmona 0:1a819403fbb3 7 Baud rate: 9600
gerardo_carmona 0:1a819403fbb3 8
gerardo_carmona 0:1a819403fbb3 9
gerardo_carmona 0:1a819403fbb3 10
gerardo_carmona 0:1a819403fbb3 11 */
gerardo_carmona 0:1a819403fbb3 12
gerardo_carmona 0:1a819403fbb3 13
gerardo_carmona 0:1a819403fbb3 14 #include "mbed.h"
gerardo_carmona 0:1a819403fbb3 15
gerardo_carmona 0:1a819403fbb3 16 DigitalOut myled(LED_GREEN);
gerardo_carmona 0:1a819403fbb3 17 Serial pc(USBTX, USBRX);
gerardo_carmona 0:1a819403fbb3 18 Serial bt(PTE0, PTE1);
gerardo_carmona 0:1a819403fbb3 19
gerardo_carmona 0:1a819403fbb3 20
gerardo_carmona 0:1a819403fbb3 21 int main(){
gerardo_carmona 0:1a819403fbb3 22 int i = 0;
gerardo_carmona 0:1a819403fbb3 23 pc.printf("Hello World!\n");
gerardo_carmona 0:1a819403fbb3 24 myled = 1;
gerardo_carmona 0:1a819403fbb3 25
gerardo_carmona 0:1a819403fbb3 26 while (true) {
gerardo_carmona 0:1a819403fbb3 27 wait(0.5f); // wait a small period of time
gerardo_carmona 0:1a819403fbb3 28 pc.printf("%d \n", i); // print the value of variable i
gerardo_carmona 0:1a819403fbb3 29 bt.printf("%d \n", i); // print the value of variable i
gerardo_carmona 0:1a819403fbb3 30 i++; // increment the variable
gerardo_carmona 0:1a819403fbb3 31
gerardo_carmona 0:1a819403fbb3 32 if (bt.readable()){
gerardo_carmona 0:1a819403fbb3 33 char c = bt.getc();
gerardo_carmona 0:1a819403fbb3 34 if (c == 'H' || c == 'h'){
gerardo_carmona 0:1a819403fbb3 35 myled = 0;
gerardo_carmona 0:1a819403fbb3 36 }else if (c == 'L' || 'l'){
gerardo_carmona 0:1a819403fbb3 37 myled = 1;
gerardo_carmona 0:1a819403fbb3 38 }
gerardo_carmona 0:1a819403fbb3 39 }
gerardo_carmona 0:1a819403fbb3 40 }
gerardo_carmona 0:1a819403fbb3 41 }