water sansor 1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
paris8022
Date:
Fri Oct 27 07:27:57 2017 +0000
Parent:
0:2b430503298a
Commit message:
123

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
sensor.h Show annotated file Show diff for this revision Revisions of this file
watersensor.h Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Oct 27 03:54:15 2017 +0000
+++ b/main.cpp	Fri Oct 27 07:27:57 2017 +0000
@@ -1,18 +1,18 @@
 #include "mbed.h"
 
-PwmOut mypwm(PWM_OUT);
+DigitalOut ledpin(LED1); 
+DigitalIn  sensor_in(D7); 
 
-DigitalOut myled(LED1);
+
 
-int main() {
-    
-    mypwm.period_ms(10);
-    mypwm.pulsewidth_ms(1);
-  
-    printf("pwm set to %.2f %%\n", mypwm.read() * 100);
-    
+int main(){
+      
     while(1) {
-        myled = !myled;
-        wait(1);
-    }
-}
+        // LEDs are ON
+        ledpin = 1;
+        wait(1.2);
+        // LEDs are OFF
+        ledpin = 0;
+        wait(1.4);
+  }
+}
\ No newline at end of file
--- a/sensor.h	Fri Oct 27 03:54:15 2017 +0000
+++ b/sensor.h	Fri Oct 27 07:27:57 2017 +0000
@@ -1,12 +1,10 @@
 int ledPin = 13; //連接13針上的LED,或者使用板載的LED
 int sensor_in = 2; //將濁度傳感器連接到數字引腳2
+int pinMode(ledPin,OUTPUT); //將ledPin設為輸出模式
+int pinMode(sensor_in,INPUT); //將濁度傳感器引腳設置為輸入模式
 
-void setup(){
-  pinMode(ledPin,OUTPUT); //將ledPin設為輸出模式
-  pinMode(sensor_in,INPUT); //將濁度傳感器引腳設置為輸入模式
-}
 
-void loop(){
+while()
    if(digitalRead(sensor_in)== LOW){//讀取傳感器信號 
         digitalWrite(ledPin,HIGH); //如果傳感器為低電平,則開啟
      }else{
--- a/watersensor.h	Fri Oct 27 03:54:15 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-const int VAL_PROBE = 0;
-const int ledPin = 13;
-
-void setup(){
-  pinMode(ledPin,OUTPUT); 
-  pinMode(sensor_in,INPUT); 
-}
-
-void loop(){
-   if(digitalRead(sensor_in)== LOW){
-        digitalWrite(ledPin,HIGH); 
-     }else{
-        digitalWrite(ledPin,LOW); 
-     }
-}
\ No newline at end of file