A library for the MQ2 sensor. Based on https://github.com/labay11 and http://sandboxelectronics.com/?p=165
Dependents: Detection_incendie
Revision 8:6eba34552ceb, committed 2021-06-22
- Comitter:
- emelinegen
- Date:
- Tue Jun 22 12:34:07 2021 +0000
- Parent:
- 7:944051b30179
- Commit message:
- d
Changed in this revision
MQ2.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 944051b30179 -r 6eba34552ceb MQ2.cpp --- a/MQ2.cpp Wed Nov 08 10:43:37 2017 +0000 +++ b/MQ2.cpp Tue Jun 22 12:34:07 2021 +0000 @@ -59,7 +59,8 @@ float val=0; for (int i=0;i<CALIBARAION_SAMPLE_TIMES;i++) { //take multiple samples val += MQResistanceCalculation(_pin.read_u16()>>6); - wait_ms(CALIBRATION_SAMPLE_INTERVAL); + //wait_ms(CALIBRATION_SAMPLE_INTERVAL); + ThisThread::sleep_for(50ms); } val = val/CALIBARAION_SAMPLE_TIMES; //calculate the average value val = val/RO_CLEAN_AIR_FACTOR; //divided by RO_CLEAN_AIR_FACTOR yields the Ro according to the chart in the datasheet @@ -79,7 +80,8 @@ float rs=0; for (i=0;i<READ_SAMPLE_TIMES;i++) { rs += MQResistanceCalculation(_pin.read_u16()>>6); - wait_ms(READ_SAMPLE_INTERVAL); + //wait_ms(READ_SAMPLE_INTERVAL); + ThisThread::sleep_for(50ms); } rs = rs/READ_SAMPLE_TIMES; return rs;