This code allows obtain the values (X,Y,Z accelerometer - Android) sent to a bluetooth module and in the same time allows see in a LCD 16*2 the state (X,Y,Z) of a the phone

Dependencies:   TextLCD mbed

Fork of LCD_FRDM_KL25Z by Gustavo Ramirez

Files at this revision

API Documentation at this revision

Comitter:
stevenjigo
Date:
Fri Oct 24 16:34:25 2014 +0000
Parent:
0:a6771cc1a056
Commit message:
This code allows obtain the values (X,Y,Z of a accelerometer - Android) sent to a bluetooth module and in the same time allows see in a LCD 16*2 the state (on or off) of a Led of the Freescale

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Sep 03 16:16:26 2013 +0000
+++ b/main.cpp	Fri Oct 24 16:34:25 2014 +0000
@@ -4,8 +4,162 @@
 #include "mbed.h"
 #include "TextLCD.h"
 
-TextLCD lcd(PTE0, PTE1, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
+//Serial pc(USBTX, USBRX); // tx, rx
+Serial device(D14, D15);  // tx, rx
+PwmOut L1(LED1);
+PwmOut L2(LED2);
+PwmOut L3(LED3);
+
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
+float t=0.3;
+
+char value;
+char inX1;
+char inX2;
+char inX3;
+char inX4;
+char inX5;
+char inY1;
+char inY2;
+char inY3;
+char inY4;
+char inY5;
+char inZ1;
+char inZ2;
+char inZ3;
+char inZ4;
+char inZ5;
+
+float inX;
+float inY;
+float inZ;
+int aux;
 
 int main() {
-    lcd.printf("Hello World!\n");
+    lcd.locate(0,0);
+    lcd.printf("Bienvenido");
+    lcd.locate(0,1);
+    lcd.printf("Acelerometro");
+    wait(2);
+    lcd.cls();
+    lcd.printf("Procesadores");
+    lcd.locate(0,1);
+    lcd.printf("Oscar y Steven");
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("X=");
+    lcd.locate(8,0);
+    lcd.printf("Y=");
+    lcd.locate(0,1);
+    lcd.printf("Z=");
+    while(1){
+        if(device.readable()) {
+            value=device.getc();
+            //pc.putc(value);
+            if(device.getc()=='X'){
+                fflush(stdin);
+                inX1=device.getc();
+                inX2=device.getc();
+                inX3=device.getc();
+                inX4=device.getc();
+                inX5=device.getc();
+                if(inX1=='X')inX1=0;
+                if(inX2=='X')inX2=0;
+                if(inX3=='X')inX3=0;
+                if(inX4=='X')inX4=0;
+                if(inX5=='X')inX5=0;
+                lcd.locate(0,0);
+                lcd.printf("X=");
+                lcd.locate(2,0);
+                lcd.printf("%c%c%c%c%c",inX1,inX2,inX3,inX4,inX5);
+            }
+            if(device.getc()=='Y'){
+                fflush(stdin);
+                inY1=device.getc();
+                inY2=device.getc();
+                inY3=device.getc();
+                inY4=device.getc();
+                inY5=device.getc();
+                if(inY1=='Y')inY1=0;
+                if(inY2=='Y')inY2=0;
+                if(inY3=='Y')inY3=0;
+                if(inY4=='Y')inY4=0;
+                if(inY5=='Y')inY5=0;
+                lcd.locate(8,0);
+                lcd.printf("Y=");
+                lcd.locate(10,0);
+                lcd.printf("%c%c%c%c%c",inY1,inY2,inY3,inY4,inY5);
+            }
+            if(device.getc()=='Z'){
+                fflush(stdin);
+                inZ1=device.getc();
+                inZ2=device.getc();
+                inZ3=device.getc();
+                inZ4=device.getc();
+                inZ5=device.getc();
+                if(inZ1=='Z')inZ1=0;
+                if(inZ2=='Z')inZ2=0;
+                if(inZ3=='Z')inZ3=0;
+                if(inZ4=='Z')inZ4=0;
+                if(inZ5=='Z')inZ5=0;
+                lcd.locate(0,1);
+                lcd.printf("Z=");
+                lcd.locate(2,1);
+                lcd.printf("%c%c%c%c%c",inZ1,inZ2,inZ3,inZ4,inZ5);
+            }
+        }
+        
+// Acondicionamiento de la señal en X del acelerometro
+        
+        if((inX1=='-')&&(inX3=='.')){
+        inX=((inX2-48)*100+(inX4-48)*10+(inX5-48)*1)*(-1);
+        }
+        if(inX2=='.'){
+        inX=(inX1-48)*100+(inX3-48)*10+(inX4-48)*1+(inX5-48)*0.1;    
+        }
+        if((inX3=='.')&&(inX1=='1')){
+        inX=(inX1-48)*1000+(inX2-48)*100+(inX4-48)*10+(inX5-48)*1;    
+        }
+        if((inX4=='.')&&(inX1=='-')){
+        inX=((inX2-48)*1000+(inX3-48)*100+(inX5-48)*10)*(-1);    
+        }
+        inX=(inX+1000)/2000;
+        L1=inX;
+        
+// Acondicionamiento de la señal en Y del acelerometro
+        
+        if((inY1=='-')&&(inY3=='.')){
+        inY=(inY2-48)*100+(inY4-48)*10+(inY5-48)*1;
+        }
+        if(inY2=='.'){
+        inY=(inY1-48)*100+(inY3-48)*10+(inY4-48)*1+(inY5-48)*0.1;    
+        }
+        if((inY3=='.')&&(inY1=='1')){
+        inY=(inY1-48)*1000+(inY2-48)*100+(inY4-48)*10+(inY5-48)*1;    
+        }
+        if((inY4=='.')&&(inY1=='-')){
+        inY=(inY2-48)*1000+(inY3-48)*100+(inY5-48)*10;    
+        }
+        inY=(inY+1000)/2000;
+        L2=inY;
+        
+// Acondicionamiento de la señal en Z del acelerometro
+        
+        if((inZ1=='-')&&(inZ3=='.')){
+        inZ=((inZ2-48)*100+(inZ4-48)*10+(inZ5-48)*1)*(-1);
+        }
+        if(inZ2=='.'){
+        inZ=(inZ1-48)*100+(inZ3-48)*10+(inZ4-48)*1+(inZ5-48)*0.1;    
+        }
+        if((inZ3=='.')&&(inZ1=='1')){
+        inZ=(inZ1-48)*1000+(inZ2-48)*100+(inZ4-48)*10+(inZ5-48)*1;    
+        }
+        if((inZ4=='.')&&(inZ1=='-')){
+        inZ=((inZ2-48)*1000+(inZ3-48)*100+(inZ5-48)*10)*(-1);    
+        }
+        inZ=(inZ+1000)/2000;
+        L3=inZ;
+        
+    }
 }