Gy_39 demo

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
rozendhyan
Date:
Thu Aug 24 17:02:12 2017 +0000
Commit message:
gy_39 demo

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c105fad1f12b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Aug 24 17:02:12 2017 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+#define size 14
+Serial pc(USBTX,USBRX);
+Serial sensor(PA_9,PA_10);
+int commend[3] = {0xA5,0x52,0xF7 };
+char buf[size];
+int Lux,Temp,Preesure,Hum,Height;
+void judgement_data(char buf[]){
+    int i=0;
+    if(buf[i++]== 0x5A){
+        //pc.printf("first_step\n");
+        if(buf[i++]== 0x5A){
+            //pc.printf("second_step\n");
+           //i++;//go to data type
+            if(buf[i] == 0x15){
+                pc.printf("Lux type\n");
+                i++;//04
+                Lux = ((buf[i+1]<<24) | (buf[i+2]<<16) | (buf[i+3]<<8) | buf[i+4])/100;
+                //Lux = (0x00<<24) | (0x00<<16) | (0xFE<<8) | 0x40;//test
+                pc.printf("Lux = %d\n", Lux);
+            }else if(buf[i] == 0x45){
+                pc.printf("temp type\n");
+                i++;//0A
+                Temp = ((buf[i+1]<<8)|(buf[i+2]))/100;
+                Preesure = ((buf[i+3]<<24)|(buf[i+4]<<16)|(buf[i+5]<<8)|(buf[i+6]))/100;
+                Hum = ((buf[i+7]<<8)|(buf[i+8]))/100;
+                Height = ((buf[i+9]<<8)|(buf[i+10]));
+                pc.printf("Temp = %d\n", Temp);
+                pc.printf("Preesure = %d\n", Preesure);
+                pc.printf("Hum = %d\n", Hum);
+                pc.printf("Height = %d\n", Height);
+            }
+        }
+    }
+}
+
+int main(){
+    pc.baud(9600);
+    //pc.printf("testing use serial port\n");
+    while(1){
+        for(int i=0;i<3;i++){
+            pc.putc(commend[i]);
+            sensor.putc(commend[i]);
+        }
+         
+        for(int i=0;i<size;i++){
+            buf[i] = sensor.getc();  
+            pc.putc(buf[i]);
+        }
+        pc.printf("\n");//enter
+        judgement_data(buf);
+        wait(3);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r c105fad1f12b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Aug 24 17:02:12 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/e2bfab296f20
\ No newline at end of file