Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #define size 14 00003 Serial pc(USBTX,USBRX); 00004 Serial sensor(PA_9,PA_10); 00005 int commend[3] = {0xA5,0x52,0xF7 }; 00006 char buf[size]; 00007 int Lux,Temp,Preesure,Hum,Height; 00008 void judgement_data(char buf[]){ 00009 int i=0; 00010 if(buf[i++]== 0x5A){ 00011 //pc.printf("first_step\n"); 00012 if(buf[i++]== 0x5A){ 00013 //pc.printf("second_step\n"); 00014 //i++;//go to data type 00015 if(buf[i] == 0x15){ 00016 pc.printf("Lux type\n"); 00017 i++;//04 00018 Lux = ((buf[i+1]<<24) | (buf[i+2]<<16) | (buf[i+3]<<8) | buf[i+4])/100; 00019 //Lux = (0x00<<24) | (0x00<<16) | (0xFE<<8) | 0x40;//test 00020 pc.printf("Lux = %d\n", Lux); 00021 }else if(buf[i] == 0x45){ 00022 pc.printf("temp type\n"); 00023 i++;//0A 00024 Temp = ((buf[i+1]<<8)|(buf[i+2]))/100; 00025 Preesure = ((buf[i+3]<<24)|(buf[i+4]<<16)|(buf[i+5]<<8)|(buf[i+6]))/100; 00026 Hum = ((buf[i+7]<<8)|(buf[i+8]))/100; 00027 Height = ((buf[i+9]<<8)|(buf[i+10])); 00028 pc.printf("Temp = %d\n", Temp); 00029 pc.printf("Preesure = %d\n", Preesure); 00030 pc.printf("Hum = %d\n", Hum); 00031 pc.printf("Height = %d\n", Height); 00032 } 00033 } 00034 } 00035 } 00036 00037 int main(){ 00038 pc.baud(9600); 00039 //pc.printf("testing use serial port\n"); 00040 while(1){ 00041 for(int i=0;i<3;i++){ 00042 pc.putc(commend[i]); 00043 sensor.putc(commend[i]); 00044 } 00045 00046 for(int i=0;i<size;i++){ 00047 buf[i] = sensor.getc(); 00048 pc.putc(buf[i]); 00049 } 00050 pc.printf("\n");//enter 00051 judgement_data(buf); 00052 wait(3); 00053 } 00054 }
Generated on Fri Aug 12 2022 19:10:00 by
1.7.2