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.
main.cpp@0:1f30d2df739e, 2016-10-14 (annotated)
- Committer:
- rkuo2000
- Date:
- Fri Oct 14 08:19:45 2016 +0000
- Revision:
- 0:1f30d2df739e
- Child:
- 1:605a7fdd4e93
ADC0 reading gas sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkuo2000 | 0:1f30d2df739e | 1 | // NuMaker-PFM-NUC472 use ADC0 (A0) to read gas sensor (MQ-3) |
rkuo2000 | 0:1f30d2df739e | 2 | #include "mbed.h" |
rkuo2000 | 0:1f30d2df739e | 3 | |
rkuo2000 | 0:1f30d2df739e | 4 | AnalogIn adc0(A0); // connected to MQ-3 gas sensor |
rkuo2000 | 0:1f30d2df739e | 5 | DigitalOut led(LED1); |
rkuo2000 | 0:1f30d2df739e | 6 | |
rkuo2000 | 0:1f30d2df739e | 7 | int main(void) |
rkuo2000 | 0:1f30d2df739e | 8 | { |
rkuo2000 | 0:1f30d2df739e | 9 | printf("ADC0 start reading...\n\r"); |
rkuo2000 | 0:1f30d2df739e | 10 | while (1) { |
rkuo2000 | 0:1f30d2df739e | 11 | printf("ADC0 value= 0x%4x, percentage= %3.3f%%\n\r",adc0.read_u16(), adc0.read()*100.0f); |
rkuo2000 | 0:1f30d2df739e | 12 | if(adc0 > 0.7f) led = 0; // > 0.7 * Vcc wil turn on led |
rkuo2000 | 0:1f30d2df739e | 13 | else led = 1; |
rkuo2000 | 0:1f30d2df739e | 14 | wait(0.2f); |
rkuo2000 | 0:1f30d2df739e | 15 | } |
rkuo2000 | 0:1f30d2df739e | 16 | } |