模拟量输入-电位器

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
anywill
Date:
Wed Oct 19 13:49:54 2016 +0000
Commit message:
?????potentiometer

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1082d8e6442f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 19 13:49:54 2016 +0000
@@ -0,0 +1,28 @@
+//平台nucleo+mbed
+//实验内容:GPIO读取电位器电压
+//A0接电位器输出端 一端接3.3v 另一端接GND
+//注:由于电阻发热实际输入最大显示不了3300
+#include "mbed.h"
+ 
+AnalogIn analog_value(A0);//读取模拟值
+ 
+DigitalOut led(LED1);     //D13 板载LED
+
+int main() {
+    float meas; 
+    
+    printf("\nAnalogIn example\n");
+    
+    while(1) {
+        meas = analog_value.read(); // 转换并读取输入的模拟量 (value from 0.0 to 1.0)
+        meas = meas * 3300; // 将模拟量映射到 0 to 3300mv 
+        printf("measure = %.0f mV\n", meas);
+        if (meas > 2000) { // 若输入电压大于2V则点亮LED 
+          led = 1;       
+        }
+        else {
+          led = 0;
+        }
+        wait(1); // 1s
+    }
+}
diff -r 000000000000 -r 1082d8e6442f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 19 13:49:54 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file