comunicacion bluetooth

Dependencies:   SoftSerial TextLCD mbed

Fork of String_BT by Marvin Villamizar

Committer:
Luisv
Date:
Sat Mar 18 19:50:24 2017 +0000
Revision:
3:03a43a82eafd
Parent:
2:38579897448f
laboratorio lcd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dimmu8410 2:38579897448f 1 #include "TextLCD.h"
dimmu8410 0:b693dce679a4 2 #include "mbed.h"
dimmu8410 0:b693dce679a4 3 #include "SoftSerial.h"
dimmu8410 0:b693dce679a4 4 #include <string>
dimmu8410 0:b693dce679a4 5 int ledPin = 13;
dimmu8410 0:b693dce679a4 6 string readString;
dimmu8410 2:38579897448f 7 int conta=0;
dimmu8410 2:38579897448f 8 int ban=0;
dimmu8410 0:b693dce679a4 9 char c[125];
dimmu8410 0:b693dce679a4 10 AnalogIn ai(A0);
dimmu8410 0:b693dce679a4 11 float measure;
dimmu8410 0:b693dce679a4 12 SoftSerial BT(D2,D3);
dimmu8410 0:b693dce679a4 13 Serial pc(USBTX,USBRX);
dimmu8410 0:b693dce679a4 14 DigitalOut led(LED2);
Luisv 3:03a43a82eafd 15 TextLCD lcd(PA_11, PA_12, PB_13, PB_14, PB_15, PB_1);
dimmu8410 0:b693dce679a4 16 int main()
dimmu8410 0:b693dce679a4 17 {
dimmu8410 2:38579897448f 18 lcd.locate(0,0);
dimmu8410 2:38579897448f 19 wait(0.1);
dimmu8410 2:38579897448f 20 lcd.locate(0,0);
dimmu8410 0:b693dce679a4 21 pc.baud(9600);
dimmu8410 0:b693dce679a4 22 BT.baud(9600);
dimmu8410 0:b693dce679a4 23 while(1)
dimmu8410 0:b693dce679a4 24 {
dimmu8410 0:b693dce679a4 25 while (BT.readable()>0)
dimmu8410 0:b693dce679a4 26 {
dimmu8410 0:b693dce679a4 27 wait(0.003);
dimmu8410 0:b693dce679a4 28 //char c = BT.getC();
dimmu8410 1:34f5a73ebf6c 29 BT.gets(c,2);
dimmu8410 0:b693dce679a4 30 readString += c;
dimmu8410 0:b693dce679a4 31 }
dimmu8410 0:b693dce679a4 32 if (readString.length()>0)
dimmu8410 0:b693dce679a4 33 {
dimmu8410 1:34f5a73ebf6c 34 pc.printf("%s",readString);
dimmu8410 2:38579897448f 35 lcd.printf("%s",readString);
dimmu8410 2:38579897448f 36 wait(0.05);
dimmu8410 2:38579897448f 37 conta+=1;
dimmu8410 2:38579897448f 38 if((ban==1)&&(conta>15))
dimmu8410 2:38579897448f 39 {
dimmu8410 2:38579897448f 40 ban=0;
dimmu8410 2:38579897448f 41 conta=0;
dimmu8410 2:38579897448f 42 lcd.cls();
dimmu8410 2:38579897448f 43 lcd.locate(0,0);
dimmu8410 2:38579897448f 44 }
dimmu8410 2:38579897448f 45 if(conta>15)
dimmu8410 2:38579897448f 46 {
dimmu8410 2:38579897448f 47 lcd.locate(0,1);
dimmu8410 2:38579897448f 48 conta=0;
dimmu8410 2:38579897448f 49 ban=1;
dimmu8410 2:38579897448f 50 }
dimmu8410 2:38579897448f 51
dimmu8410 1:34f5a73ebf6c 52 //pc.printf("%s\r\n",readString);
dimmu8410 1:34f5a73ebf6c 53 if (readString == "1")
dimmu8410 0:b693dce679a4 54 {
dimmu8410 1:34f5a73ebf6c 55 led=!led;
dimmu8410 1:34f5a73ebf6c 56 wait(0.5);
dimmu8410 0:b693dce679a4 57 }
dimmu8410 0:b693dce679a4 58 if (readString == "FO")
dimmu8410 0:b693dce679a4 59 {
dimmu8410 0:b693dce679a4 60 led=0;
dimmu8410 0:b693dce679a4 61 }
dimmu8410 1:34f5a73ebf6c 62 if (readString == ".")
dimmu8410 1:34f5a73ebf6c 63 {
dimmu8410 1:34f5a73ebf6c 64 pc.printf("\n\r");
dimmu8410 1:34f5a73ebf6c 65 }
dimmu8410 0:b693dce679a4 66 if (readString == "AL")
dimmu8410 0:b693dce679a4 67 {
dimmu8410 0:b693dce679a4 68 measure=ai.read_u16()*0.00005;
dimmu8410 0:b693dce679a4 69 BT.printf("%f",measure);
dimmu8410 0:b693dce679a4 70 }
dimmu8410 0:b693dce679a4 71 readString="";
dimmu8410 1:34f5a73ebf6c 72 c[0]=' ';
dimmu8410 1:34f5a73ebf6c 73 c[1]=' ';
dimmu8410 1:34f5a73ebf6c 74 c[2]=' ';
dimmu8410 0:b693dce679a4 75 }
dimmu8410 0:b693dce679a4 76 }
dimmu8410 0:b693dce679a4 77 }