Bluetooth, conexion LCD

Dependencies:   SoftSerial TextLCD mbed

Fork of String_BT by Marvin Villamizar

Files at this revision

API Documentation at this revision

Comitter:
Innom
Date:
Sat Mar 18 19:24:51 2017 +0000
Parent:
2:38579897448f
Commit message:
Pantalla LCD 16x2, Conexion Bluethoot

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 38579897448f -r 6dddc15f7dff main.cpp
--- a/main.cpp	Wed Mar 15 00:16:44 2017 +0000
+++ b/main.cpp	Sat Mar 18 19:24:51 2017 +0000
@@ -1,18 +1,22 @@
+/******************************************************************************/
 #include "TextLCD.h"
 #include "mbed.h"
 #include "SoftSerial.h"
 #include <string>
+/******************************************************************************/
 int ledPin = 13;
 string readString;
 int conta=0;
 int ban=0;
 char c[125];
+float measure;
+/******************************************************************************/
 AnalogIn ai(A0);
-float measure;
 SoftSerial BT(D2,D3);
 Serial pc(USBTX,USBRX);
-DigitalOut led(LED2);
+//DigitalOut led(LED2);
 TextLCD lcd(D4,D5,D6,D7,D8,D9);
+/******************************************************************************/
 int main() 
 {
   lcd.locate(0,0);
@@ -20,58 +24,56 @@
   lcd.locate(0,0);
   pc.baud(9600);
   BT.baud(9600);
+  BT.printf("AT+NAMESinNombre");
+  wait(1);
+  lcd.cls();
   while(1)
   {
    while (BT.readable()>0) 
-   {
-    wait(0.003);  
-    //char c = BT.getC();
-    BT.gets(c,2);
-    readString += c; 
-  }
-  if (readString.length()>0) 
-  {
-    pc.printf("%s",readString);
-    lcd.printf("%s",readString);
-    wait(0.05);
-    conta+=1;
-    if((ban==1)&&(conta>15))
     {
-     ban=0;
-     conta=0;
-     lcd.cls();
-     lcd.locate(0,0);   
-    }
-    if(conta>15)
-    {
-     lcd.locate(0,1);
-     conta=0;
-     ban=1;   
+        wait(0.003);  
+        //char c = BT.getC();
+        BT.gets(c,2);
+        readString += c; 
     }
-    
-    //pc.printf("%s\r\n",readString);
-    if (readString == "1")     
-    {
-      led=!led;
-      wait(0.5);
-    }
-    if (readString == "FO")
-    {
-      led=0;
-    }
-    if (readString == ".")
-    {
-      pc.printf("\n\r");
-    }
-    if (readString == "AL")
-    {
-      measure=ai.read_u16()*0.00005;
-      BT.printf("%f",measure);
-    }
-    readString="";
-    c[0]=' ';
-    c[1]=' ';
-    c[2]=' ';
-  } 
-}
+      if (readString.length()>0) 
+      {
+        pc.printf("%s",readString);
+        lcd.printf("%s",readString);
+        wait(0.05);
+        conta+=1;
+        if((ban==1)&&(conta>15))
+        {
+             ban=0;
+             conta=0;
+             lcd.cls();
+             lcd.locate(0,0);   
+        }
+        if(conta>15)
+        {
+             lcd.locate(0,1);
+             conta=0;
+             ban=1;   
+        }
+        for (int i=0; i<125; i++)
+        {
+        if((c[i] == 10)&&(ban==0))
+        {
+             lcd.locate(0,1);
+             conta=0;
+             ban=1;
+        }
+        if(c[i] == 127)
+        {
+             //lcd.printf("");
+             lcd.cls();
+             conta=0;
+        }
+        }
+        readString="";
+        c[0]=' ';
+        c[1]=' ';
+        c[2]=' ';
+    } 
+  }
 }
\ No newline at end of file