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.
Dependencies: Grove_Air_Quality_Sensor_Library mbed
main.cpp@1:888328032581, 2014-09-05 (annotated)
- Committer:
- mbedAustin
- Date:
- Fri Sep 05 19:17:20 2014 +0000
- Revision:
- 1:888328032581
- Parent:
- 0:2dbce8e35862
- Child:
- 2:225383599b95
Added interrupt driven library and made example more robust
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| mbedAustin | 1:888328032581 | 1 | |
| mbedAustin | 1:888328032581 | 2 | #include"mbed.h" | 
| mbedAustin | 1:888328032581 | 3 | #include"Air_Quality.h" | 
| mbedAustin | 1:888328032581 | 4 | AirQuality airqualitysensor; | 
| mbedAustin | 1:888328032581 | 5 | int current_quality = -1; | 
| mbedAustin | 1:888328032581 | 6 | PinName analogPin = A0; | 
| mbedAustin | 0:2dbce8e35862 | 7 | |
| mbedAustin | 1:888328032581 | 8 | // Interrupt Handler | 
| mbedAustin | 1:888328032581 | 9 | void AirQualityInterrupt() | 
| mbedAustin | 1:888328032581 | 10 | { | 
| mbedAustin | 1:888328032581 | 11 | AnalogIn sensor(analogPin); | 
| mbedAustin | 1:888328032581 | 12 | airqualitysensor.last_vol = airqualitysensor.first_vol; | 
| mbedAustin | 1:888328032581 | 13 | airqualitysensor.first_vol = sensor.read()*1000; | 
| mbedAustin | 1:888328032581 | 14 | airqualitysensor.timer_index = 1; | 
| mbedAustin | 1:888328032581 | 15 | } | 
| mbedAustin | 0:2dbce8e35862 | 16 | |
| mbedAustin | 1:888328032581 | 17 | // Main loop | 
| mbedAustin | 1:888328032581 | 18 | int main() | 
| mbedAustin | 1:888328032581 | 19 | { | 
| mbedAustin | 1:888328032581 | 20 | airqualitysensor.init(analogPin, AirQualityInterrupt); | 
| mbedAustin | 1:888328032581 | 21 | while(1) { | 
| mbedAustin | 1:888328032581 | 22 | current_quality=airqualitysensor.slope(); | 
| mbedAustin | 1:888328032581 | 23 | if (current_quality >= 0) { // if a valid data returned. | 
| mbedAustin | 1:888328032581 | 24 | if (current_quality == 0) | 
| mbedAustin | 1:888328032581 | 25 | printf("High pollution! Force signal active\n\r"); | 
| mbedAustin | 1:888328032581 | 26 | else if (current_quality == 1) | 
| mbedAustin | 1:888328032581 | 27 | printf("High pollution!\n\r"); | 
| mbedAustin | 1:888328032581 | 28 | else if (current_quality == 2) | 
| mbedAustin | 1:888328032581 | 29 | printf("Low pollution!\n\r"); | 
| mbedAustin | 1:888328032581 | 30 | else if (current_quality == 3) | 
| mbedAustin | 1:888328032581 | 31 | printf("Fresh air\n\r"); | 
| mbedAustin | 1:888328032581 | 32 | } | 
| mbedAustin | 0:2dbce8e35862 | 33 | } | 
| mbedAustin | 0:2dbce8e35862 | 34 | } |