MIDE CALIDAD DELA AIRE CON MUCHA PRESICION

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002 * Referencias
00003 * [1] https://www.dfrobot.com/wiki/index.php/PM2.5_laser_dust_sensor_SKU:SEN0177
00004 *******************************************************************************/
00005 #include "mbed.h"
00006 #include "pms1003.h"
00007  
00008 #define LENG 31   //0x42 + 31 bytes equal to 32 bytes
00009 char buf[LENG];
00010  
00011 Serial *pc     = new Serial(USBTX, USBRX); // tx, rx
00012 Serial *device = new Serial(PTE0, PTE1);   // tx, rx
00013 pms1003 *PM = new pms1003();
00014  
00015 int main() {
00016     while(1) {
00017         if(device->readable()) {//if 1
00018             //pc.putc(device.getc());
00019             if ( device->getc() == 0x42){//if 2
00020                 device->gets(buf,LENG);
00021                 
00022                 if(buf[0] == 0x4d){//if 3
00023                 
00024                     PM->setPM(buf);
00025                     pc->printf("*******************************\n");
00026                     pc->printf("PM_1.0:%4d [ug/m3]\n",PM->get_PM01Value());
00027                     pc->printf("PM_2.5:%4d [ug/m3]\n",PM->get_PM2_5Value());
00028                     pc->printf("PM__10:%4d [ug/m3]\n",PM->get_PM10Value());
00029                 }//if 3
00030             }//if 2         
00031         }//if 1        
00032     }//while
00033 }// main