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.
Revision 3:2e06207b1e90, committed 2019-03-07
- Comitter:
- roycoll
- Date:
- Thu Mar 07 14:58:39 2019 +0000
- Parent:
- 2:3a61e56476bc
- Commit message:
- Version 1, Midterm project - Vehicle Air quality warning system/safety system.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 06 09:36:16 2017 +0000
+++ b/main.cpp Thu Mar 07 14:58:39 2019 +0000
@@ -1,25 +1,44 @@
#include "mbed.h"
#include "MQ2.h"
+DigitalOut led(D2);
+PwmOut PWM1(A5);
+int on = 1, off = 0;
-Serial pc(USBTX, USBRX); // tx, rx
+Serial pc(USBTX, USBRX); // tx, rx
MQ2 mq2(A1); // Analog Port to read from
-
-int main() {
+int main()
+{
+ PWM1.period_ms(500);
+ int x; x=1;
pc.baud(115200);
mq2.begin(); // 'Calibrate' sensor
MQ2_data_t MQ2_data; // Structure to hold data.
- while (true) {
- pc.printf("CO PPM: %.0f\r\n",mq2.readCO()); // Performs a one shot read of CO
- pc.printf("Smoke PPM: %.0f\r\n",mq2.readSmoke()); // Performs a one shot read of Smoke
- pc.printf("LPG PPM: %.0f\r\n",mq2.readLPG()); // Performs a one shot read of LPG
- wait(1);
+ while (true)
+ {
+ pc.printf("CO PPM: %.0f\r\n",mq2.readCO()); // Read of CO
+ pc.printf("Smoke PPM: %.0f\r\n",mq2.readSmoke()); // Read of Smoke
+ pc.printf("LPG PPM: %.0f\r\n",mq2.readLPG()); // Read of LPG
+ wait(.1);
+ pc.printf("................................\r\n");
+ mq2.read(&MQ2_data); // Alt reading method, reading to structure
+ pc.printf("CO PPM: %.0f\r\n",MQ2_data.co); // Return data from structure
+ pc.printf("Smoke PPM: %.0f\r\n",MQ2_data.smoke); // Return data from structure
+ pc.printf("LPG PPM: %.0f\r\n",MQ2_data.lpg); // Return data from structure
pc.printf("................................\r\n");
- mq2.read(&MQ2_data); // Alt reading method, reading to struct
- pc.printf("CO PPM: %.0f\r\n",MQ2_data.co); // Return data from strut
- pc.printf("Smoke PPM: %.0f\r\n",MQ2_data.smoke); // Return data from strut
- pc.printf("LPG PPM: %.0f\r\n",MQ2_data.lpg); // Return data from strut
- pc.printf("................................\r\n");
- wait(1);
+ wait(.1);
+ if (MQ2_data.co > 300)
+ {
+ led = on;
+ PWM1.pulsewidth_ms(x);
+ x=x+1;
+ wait(.1);
+ }
+ else
+ {
+ x=0;
+ PWM1.pulsewidth_ms(x);
+ led = off;
+ }
}
}