![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Final Project for ECE-4180
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect
Diff: main.cpp
- Revision:
- 0:941787ae3c86
- Child:
- 1:5ceaf94b79e4
diff -r 000000000000 -r 941787ae3c86 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Nov 21 00:27:36 2020 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" +AnalogIn waterSensor(p20); +AnalogIn moistureSensor(p19); +AnalogIn lightSensor(p18); +Serial pc(USBTX, USBRX); // tx, rx +PwmOut speaker(p21); +PwmOut led(p22); +PwmOut warningLight(LED1); + +int main() { + pc.printf("\rstart printing\n"); + int counting = 0; + float water = 0.0; + float light = 0.0; + float moist = 0.0; + speaker.period(1.0/2000.0); + + while(1) { + water = waterSensor.read(); + moist = moistureSensor.read(); + light = lightSensor.read(); + pc.printf("%d: ",counting); + pc.printf("%f water\n\r",water); + pc.printf("%f moist\n\r",moist); + pc.printf("%f light\n\r",light); + counting++; + led.write(1-light); + + if (light<0.3){//water>0.4 //mosit<0.3 + speaker = 0.3; + warningLight.write(.5); + } + else + { + speaker = warningLight = 0; + } + wait(1); + } +}