This library is made for MQ-4 gás sensor.

Dependents:   MQ4_example Navitec-Firmware

Files at this revision

API Documentation at this revision

Comitter:
renanbmx123
Date:
Sun Apr 04 14:38:22 2021 +0000
Parent:
0:401959f72658
Commit message:
Refatorado;

Changed in this revision

MQ4.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 401959f72658 -r d64cac41351a MQ4.cpp
--- a/MQ4.cpp	Tue Jul 17 04:34:21 2018 +0000
+++ b/MQ4.cpp	Sun Apr 04 14:38:22 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(chrono::milliseconds(CALIBRATION_SAMPLE_INTERVAL));
   }
   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(chrono::milliseconds(READ_SAMPLE_INTERVAL));
   }
   rs = rs/READ_SAMPLE_TIMES;
   return rs;