final
Dependencies: mbed Servo NeoMatrix mbed-rtos 4DGL-uLCD-SE PinDetect PololuLedStrip
Diff: main.cpp
- Revision:
- 0:941787ae3c86
- Child:
- 1:5ceaf94b79e4
--- /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); + } +}