Test program for PwmReader library
Dependencies: PwmReader mbed Shinyei
main.cpp@1:e38ff2920f0e, 2017-01-26 (annotated)
- Committer:
- abouillot
- Date:
- Thu Jan 26 15:10:16 2017 +0000
- Revision:
- 1:e38ff2920f0e
- Parent:
- 0:3e9bf225bd52
Test program for Shinyei PPD42NJ particles sensor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
abouillot | 0:3e9bf225bd52 | 1 | /*! |
abouillot | 0:3e9bf225bd52 | 2 | * Test application |
abouillot | 0:3e9bf225bd52 | 3 | * |
abouillot | 1:e38ff2920f0e | 4 | * Read particle concentration using a Shinyei PPD42NJ sensor |
abouillot | 0:3e9bf225bd52 | 5 | * |
abouillot | 0:3e9bf225bd52 | 6 | * Copyright (c) 2017 - Alexandre Bouillot github.com/abouillot |
abouillot | 0:3e9bf225bd52 | 7 | * |
abouillot | 0:3e9bf225bd52 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
abouillot | 0:3e9bf225bd52 | 9 | * of this software and associated documnetation files (the "Software"), to deal |
abouillot | 0:3e9bf225bd52 | 10 | * in the Software without restriction, including without limitation the rights |
abouillot | 0:3e9bf225bd52 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
abouillot | 0:3e9bf225bd52 | 12 | * copies of the Software, and to permit persons to whom the Software is |
abouillot | 0:3e9bf225bd52 | 13 | * furished to do so, subject to the following conditions: |
abouillot | 0:3e9bf225bd52 | 14 | * |
abouillot | 0:3e9bf225bd52 | 15 | * The above copyright notice and this permission notice shall be included in |
abouillot | 0:3e9bf225bd52 | 16 | * all copies or substantial portions of the Software. |
abouillot | 0:3e9bf225bd52 | 17 | * |
abouillot | 0:3e9bf225bd52 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
abouillot | 0:3e9bf225bd52 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
abouillot | 0:3e9bf225bd52 | 20 | * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
abouillot | 0:3e9bf225bd52 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
abouillot | 0:3e9bf225bd52 | 22 | * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
abouillot | 0:3e9bf225bd52 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
abouillot | 0:3e9bf225bd52 | 24 | * THE SOFTWARE. |
abouillot | 0:3e9bf225bd52 | 25 | */ |
abouillot | 1:e38ff2920f0e | 26 | |
abouillot | 1:e38ff2920f0e | 27 | #include "mbed.h" |
abouillot | 1:e38ff2920f0e | 28 | #include "Shinyei.h" |
abouillot | 1:e38ff2920f0e | 29 | |
abouillot | 1:e38ff2920f0e | 30 | Serial pc(SERIAL_TX, SERIAL_RX); |
abouillot | 0:3e9bf225bd52 | 31 | |
abouillot | 1:e38ff2920f0e | 32 | DigitalOut myled(LED1); |
abouillot | 0:3e9bf225bd52 | 33 | |
abouillot | 1:e38ff2920f0e | 34 | // define asynch_test to demonstrate the non blocking usage |
abouillot | 1:e38ff2920f0e | 35 | //#define asynch_test |
abouillot | 1:e38ff2920f0e | 36 | #define asynch_test |
abouillot | 0:3e9bf225bd52 | 37 | |
abouillot | 1:e38ff2920f0e | 38 | #if defined(asynch_test) |
abouillot | 1:e38ff2920f0e | 39 | Shinyei shinyei(USER_BUTTON); |
abouillot | 0:3e9bf225bd52 | 40 | |
abouillot | 1:e38ff2920f0e | 41 | void completeSampling() |
abouillot | 0:3e9bf225bd52 | 42 | { |
abouillot | 1:e38ff2920f0e | 43 | printf("Concentration: %f\n", shinyei.concentration()); |
abouillot | 1:e38ff2920f0e | 44 | shinyei.startSampling(completeSampling, 30); |
abouillot | 0:3e9bf225bd52 | 45 | } |
abouillot | 1:e38ff2920f0e | 46 | #endif |
abouillot | 1:e38ff2920f0e | 47 | |
abouillot | 1:e38ff2920f0e | 48 | int main() |
abouillot | 1:e38ff2920f0e | 49 | { |
abouillot | 1:e38ff2920f0e | 50 | printf("**************** PwmReader test program ****************\n"); |
abouillot | 0:3e9bf225bd52 | 51 | |
abouillot | 1:e38ff2920f0e | 52 | #if defined(asynch_test) |
abouillot | 1:e38ff2920f0e | 53 | shinyei.startSampling(completeSampling, 30); |
abouillot | 0:3e9bf225bd52 | 54 | |
abouillot | 1:e38ff2920f0e | 55 | int i = 1; |
abouillot | 1:e38ff2920f0e | 56 | pc.printf("Hello World !\n"); |
abouillot | 1:e38ff2920f0e | 57 | while(1) { |
abouillot | 1:e38ff2920f0e | 58 | wait(1); |
abouillot | 1:e38ff2920f0e | 59 | pc.printf(".", i++, shinyei.concentration()); |
abouillot | 1:e38ff2920f0e | 60 | myled = !myled; |
abouillot | 0:3e9bf225bd52 | 61 | } |
abouillot | 1:e38ff2920f0e | 62 | #else |
abouillot | 1:e38ff2920f0e | 63 | Shinyei shinyei(USER_BUTTON); |
abouillot | 1:e38ff2920f0e | 64 | while (1) { |
abouillot | 1:e38ff2920f0e | 65 | shinyei.startSampling(30); |
abouillot | 1:e38ff2920f0e | 66 | |
abouillot | 1:e38ff2920f0e | 67 | while (!shinyei.dataReady()) { |
abouillot | 1:e38ff2920f0e | 68 | pc.printf("."); |
abouillot | 1:e38ff2920f0e | 69 | wait(.5); |
abouillot | 1:e38ff2920f0e | 70 | } |
abouillot | 1:e38ff2920f0e | 71 | wait(5); |
abouillot | 1:e38ff2920f0e | 72 | pc.printf("\n"); |
abouillot | 1:e38ff2920f0e | 73 | |
abouillot | 1:e38ff2920f0e | 74 | pc.printf("Concentration: %f\n", shinyei.concentration()); |
abouillot | 0:3e9bf225bd52 | 75 | } |
abouillot | 1:e38ff2920f0e | 76 | #endif |
abouillot | 0:3e9bf225bd52 | 77 | } |
abouillot | 0:3e9bf225bd52 | 78 | |
abouillot | 0:3e9bf225bd52 | 79 |