zeus 3110
/
MH-Z19_Test
CO2 Sensor MH-Z19 Class (uses interrupt input as PWM input)
MH_Z19.h@0:3c154d34f47e, 2016-08-11 (annotated)
- Committer:
- zeus3110
- Date:
- Thu Aug 11 00:41:23 2016 +0000
- Revision:
- 0:3c154d34f47e
Initial Release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zeus3110 | 0:3c154d34f47e | 1 | /* mbed MH-Z19 Library |
zeus3110 | 0:3c154d34f47e | 2 | * Copyright (c) 2016, zeus3110 |
zeus3110 | 0:3c154d34f47e | 3 | * |
zeus3110 | 0:3c154d34f47e | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
zeus3110 | 0:3c154d34f47e | 5 | * of this software and associated documentation files (the "Software"), to deal |
zeus3110 | 0:3c154d34f47e | 6 | * in the Software without restriction, including without limitation the rights |
zeus3110 | 0:3c154d34f47e | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
zeus3110 | 0:3c154d34f47e | 8 | * copies of the Software, and to permit persons to whom the Software is |
zeus3110 | 0:3c154d34f47e | 9 | * furnished to do so, subject to the following conditions: |
zeus3110 | 0:3c154d34f47e | 10 | * |
zeus3110 | 0:3c154d34f47e | 11 | * The above copyright notice and this permission notice shall be included in |
zeus3110 | 0:3c154d34f47e | 12 | * all copies or substantial portions of the Software. |
zeus3110 | 0:3c154d34f47e | 13 | * |
zeus3110 | 0:3c154d34f47e | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
zeus3110 | 0:3c154d34f47e | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
zeus3110 | 0:3c154d34f47e | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
zeus3110 | 0:3c154d34f47e | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
zeus3110 | 0:3c154d34f47e | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
zeus3110 | 0:3c154d34f47e | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
zeus3110 | 0:3c154d34f47e | 20 | * THE SOFTWARE. |
zeus3110 | 0:3c154d34f47e | 21 | */ |
zeus3110 | 0:3c154d34f47e | 22 | |
zeus3110 | 0:3c154d34f47e | 23 | #ifndef MH_Z19_H |
zeus3110 | 0:3c154d34f47e | 24 | #define MH_Z19_H |
zeus3110 | 0:3c154d34f47e | 25 | |
zeus3110 | 0:3c154d34f47e | 26 | #include "mbed.h" |
zeus3110 | 0:3c154d34f47e | 27 | |
zeus3110 | 0:3c154d34f47e | 28 | #define PWM_CYCLE_MS 1004 |
zeus3110 | 0:3c154d34f47e | 29 | #define CO2_MAX_PPM 5000 |
zeus3110 | 0:3c154d34f47e | 30 | |
zeus3110 | 0:3c154d34f47e | 31 | class MH_Z19 { |
zeus3110 | 0:3c154d34f47e | 32 | public: |
zeus3110 | 0:3c154d34f47e | 33 | /** Create a MH_Z19 |
zeus3110 | 0:3c154d34f47e | 34 | * |
zeus3110 | 0:3c154d34f47e | 35 | * @param Port The pwm input pin (must support InterruptIn) |
zeus3110 | 0:3c154d34f47e | 36 | */ |
zeus3110 | 0:3c154d34f47e | 37 | MH_Z19(PinName Port); |
zeus3110 | 0:3c154d34f47e | 38 | |
zeus3110 | 0:3c154d34f47e | 39 | int ReadCO2PPM(); |
zeus3110 | 0:3c154d34f47e | 40 | |
zeus3110 | 0:3c154d34f47e | 41 | protected: |
zeus3110 | 0:3c154d34f47e | 42 | void rise(); |
zeus3110 | 0:3c154d34f47e | 43 | void fall(); |
zeus3110 | 0:3c154d34f47e | 44 | |
zeus3110 | 0:3c154d34f47e | 45 | InterruptIn Port; |
zeus3110 | 0:3c154d34f47e | 46 | Timer T; |
zeus3110 | 0:3c154d34f47e | 47 | int OnWidth; |
zeus3110 | 0:3c154d34f47e | 48 | }; |
zeus3110 | 0:3c154d34f47e | 49 | |
zeus3110 | 0:3c154d34f47e | 50 | #endif |