アナログ入力_振動センサ

Dependencies:   TextLCD mbed

振動センサに入力があるとLEDを点灯

参考 https://mbed.org/users/okini3939/notebook/AnalogIn_jp/

Revision:
0:18ca468a910f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 23 10:34:13 2014 +0000
@@ -0,0 +1,21 @@
+#include "mbed.h"
+
+AnalogIn ain(p15);
+DigitalOut myled(p5);
+
+int main() {
+    float adc, volts;
+    
+    myled = 0;
+    
+    while (1){
+        adc = ain.read();           // read analog as a float
+        volts = adc * 3.3;          // convert to volts
+        if(volts > 1.0){
+            myled = 1;
+        }else{
+            myled = 0;
+        }
+        //wait(0.5);                 //
+    }
+}