wang tang
/
watersensor
LGZD:sensor
main.cpp@0:1bf4445f640f, 2017-10-27 (annotated)
- Committer:
- e58136782000
- Date:
- Fri Oct 27 08:23:58 2017 +0000
- Revision:
- 0:1bf4445f640f
watersensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
e58136782000 | 0:1bf4445f640f | 1 | #include "mbed.h" |
e58136782000 | 0:1bf4445f640f | 2 | |
e58136782000 | 0:1bf4445f640f | 3 | DigitalOut ledpin(LED1); |
e58136782000 | 0:1bf4445f640f | 4 | DigitalIn sensor_in(D4); |
e58136782000 | 0:1bf4445f640f | 5 | Serial serial(USBTX, USBRX); |
e58136782000 | 0:1bf4445f640f | 6 | int main(){ |
e58136782000 | 0:1bf4445f640f | 7 | |
e58136782000 | 0:1bf4445f640f | 8 | while(1) { |
e58136782000 | 0:1bf4445f640f | 9 | // LEDs are ON |
e58136782000 | 0:1bf4445f640f | 10 | if(sensor_in) |
e58136782000 | 0:1bf4445f640f | 11 | { |
e58136782000 | 0:1bf4445f640f | 12 | ledpin = 1; |
e58136782000 | 0:1bf4445f640f | 13 | serial.printf("LED:ON\n"); |
e58136782000 | 0:1bf4445f640f | 14 | wait(1.2); |
e58136782000 | 0:1bf4445f640f | 15 | } |
e58136782000 | 0:1bf4445f640f | 16 | else |
e58136782000 | 0:1bf4445f640f | 17 | { |
e58136782000 | 0:1bf4445f640f | 18 | // LEDs are OFF |
e58136782000 | 0:1bf4445f640f | 19 | ledpin = 0; |
e58136782000 | 0:1bf4445f640f | 20 | serial.printf("LED:OFF\n"); |
e58136782000 | 0:1bf4445f640f | 21 | wait(1.4); |
e58136782000 | 0:1bf4445f640f | 22 | } |
e58136782000 | 0:1bf4445f640f | 23 | } |
e58136782000 | 0:1bf4445f640f | 24 | } |