Test program for PwmReader library

Dependencies:   PwmReader mbed Shinyei

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*!
00002  * Test application
00003  *
00004  * Read particle concentration using a Shinyei PPD42NJ sensor
00005  *
00006  * Copyright (c) 2017 -  Alexandre Bouillot github.com/abouillot
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documnetation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to  whom the Software is
00013  * furished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  */
00026 
00027 #include "mbed.h"
00028 #include "Shinyei.h"
00029 
00030 Serial pc(SERIAL_TX, SERIAL_RX);
00031 
00032 DigitalOut myled(LED1);
00033 
00034 // define asynch_test to demonstrate the non blocking usage
00035 //#define asynch_test
00036 #define asynch_test
00037 
00038 #if defined(asynch_test)
00039 Shinyei shinyei(USER_BUTTON);
00040 
00041 void completeSampling()
00042 {
00043     printf("Concentration: %f\n", shinyei.concentration());
00044     shinyei.startSampling(completeSampling, 30);
00045 }
00046 #endif
00047 
00048 int main()
00049 {
00050     printf("**************** PwmReader test program ****************\n");
00051 
00052 #if defined(asynch_test)
00053     shinyei.startSampling(completeSampling, 30);
00054 
00055     int i = 1;
00056     pc.printf("Hello World !\n");
00057     while(1) {
00058         wait(1);
00059         pc.printf(".", i++, shinyei.concentration());
00060         myled = !myled;
00061     }
00062 #else
00063     Shinyei shinyei(USER_BUTTON);
00064     while (1) {
00065         shinyei.startSampling(30);
00066 
00067         while (!shinyei.dataReady()) {
00068             pc.printf(".");
00069             wait(.5);
00070         }
00071         wait(5);
00072         pc.printf("\n");
00073 
00074         pc.printf("Concentration: %f\n", shinyei.concentration());
00075     }
00076 #endif
00077 }
00078 
00079