mbed ADC read gas sensor

Files at this revision

API Documentation at this revision

Comitter:
rkuo2000
Date:
Thu Oct 20 12:31:28 2016 +0000
Commit message:
mbed ADC read sensor

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Thu Oct 20 12:31:28 2016 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 20 12:31:28 2016 +0000
@@ -0,0 +1,16 @@
+// using NuMaker-PFM-NUC472 ADC0 (A0/PE_1) to read gas sensor (MQ-3)
+#include "mbed.h"
+
+AnalogIn   adc0(PE_1); // A0 connected to MQ-3 gas sensor
+DigitalOut led(LED1);
+
+int main(void)
+{
+    printf("ADC0 start reading...\n\r");
+    while (1) { 
+        printf("ADC0 value= 0x%4x, percentage= %3.3f%%\n\r",adc0.read_u16(), adc0.read()*100.0f);
+        if(adc0 > 0.7f) led = 0; // > 0.7 * Vcc wil turn on led
+        else            led = 1;
+        wait(0.2f);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Oct 20 12:31:28 2016 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#a6f3fd1a60d5df59246d7caf3f108c4d34e1808e