Ray Liu
/
NuMaker-mbed-ADC0_MQ3
Modify the file main.cpp for M487
main.cpp@0:9a9104a3d71f, 2017-09-29 (annotated)
- Committer:
- shliu1
- Date:
- Fri Sep 29 05:41:53 2017 +0000
- Revision:
- 0:9a9104a3d71f
main.cpp adds the setting of TARGET_NUMAKER_PFM_M487 for M487
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shliu1 | 0:9a9104a3d71f | 1 | // NuMaker-PFM-NUC472 use ADC0 (A0/PE_1) to read gas sensor (MQ-3) |
shliu1 | 0:9a9104a3d71f | 2 | #include "mbed.h" |
shliu1 | 0:9a9104a3d71f | 3 | #if defined(TARGET_NUMAKER_PFM_NUC472) |
shliu1 | 0:9a9104a3d71f | 4 | AnalogIn adc0(PE_1); // A0 connected to MQ-3 gas sensor |
shliu1 | 0:9a9104a3d71f | 5 | #elif defined(TARGET_NUMAKER_PFM_M453) |
shliu1 | 0:9a9104a3d71f | 6 | AnalogIn adc0(PB_0); |
shliu1 | 0:9a9104a3d71f | 7 | #elif defined(TARGET_NUMAKER_PFM_M487) |
shliu1 | 0:9a9104a3d71f | 8 | AnalogIn adc0(PB_6); |
shliu1 | 0:9a9104a3d71f | 9 | #endif |
shliu1 | 0:9a9104a3d71f | 10 | |
shliu1 | 0:9a9104a3d71f | 11 | DigitalOut led(LED1); |
shliu1 | 0:9a9104a3d71f | 12 | |
shliu1 | 0:9a9104a3d71f | 13 | int main(void) |
shliu1 | 0:9a9104a3d71f | 14 | { |
shliu1 | 0:9a9104a3d71f | 15 | printf("ADC0 start reading...\n\r"); |
shliu1 | 0:9a9104a3d71f | 16 | while (1) { |
shliu1 | 0:9a9104a3d71f | 17 | printf("ADC0 value= 0x%4x, percentage= %3.3f%%\n\r",adc0.read_u16(), adc0.read()*100.0f); |
shliu1 | 0:9a9104a3d71f | 18 | if(adc0 > 0.7f) led = 0; // > 0.7 * Vcc wil turn on led |
shliu1 | 0:9a9104a3d71f | 19 | else led = 1; |
shliu1 | 0:9a9104a3d71f | 20 | wait(0.2f); |
shliu1 | 0:9a9104a3d71f | 21 | } |
shliu1 | 0:9a9104a3d71f | 22 | } |