![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Final Project for ECE-4180
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect
main.cpp@1:5ceaf94b79e4, 2020-11-21 (annotated)
- Committer:
- oscargao
- Date:
- Sat Nov 21 05:32:38 2020 +0000
- Revision:
- 1:5ceaf94b79e4
- Parent:
- 0:941787ae3c86
- Child:
- 2:95f72e92b370
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oscargao | 0:941787ae3c86 | 1 | #include "mbed.h" |
oscargao | 1:5ceaf94b79e4 | 2 | #include "uLCD_4DGL.h" |
oscargao | 1:5ceaf94b79e4 | 3 | #include "PinDetect.h" |
oscargao | 1:5ceaf94b79e4 | 4 | |
oscargao | 1:5ceaf94b79e4 | 5 | uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; |
oscargao | 1:5ceaf94b79e4 | 6 | |
oscargao | 1:5ceaf94b79e4 | 7 | PinDetect button(p7,PullDown); |
oscargao | 0:941787ae3c86 | 8 | AnalogIn waterSensor(p20); |
oscargao | 0:941787ae3c86 | 9 | AnalogIn moistureSensor(p19); |
oscargao | 0:941787ae3c86 | 10 | AnalogIn lightSensor(p18); |
oscargao | 0:941787ae3c86 | 11 | Serial pc(USBTX, USBRX); // tx, rx |
oscargao | 0:941787ae3c86 | 12 | PwmOut speaker(p21); |
oscargao | 0:941787ae3c86 | 13 | PwmOut led(p22); |
oscargao | 0:941787ae3c86 | 14 | PwmOut warningLight(LED1); |
oscargao | 0:941787ae3c86 | 15 | |
oscargao | 1:5ceaf94b79e4 | 16 | int led_flip = 1; |
oscargao | 1:5ceaf94b79e4 | 17 | |
oscargao | 1:5ceaf94b79e4 | 18 | void Button_Callback (void) { |
oscargao | 1:5ceaf94b79e4 | 19 | |
oscargao | 1:5ceaf94b79e4 | 20 | } |
oscargao | 1:5ceaf94b79e4 | 21 | |
oscargao | 0:941787ae3c86 | 22 | int main() { |
oscargao | 1:5ceaf94b79e4 | 23 | uLCD.printf("\n\rstart printing\n"); |
oscargao | 1:5ceaf94b79e4 | 24 | wait(1); |
oscargao | 0:941787ae3c86 | 25 | int counting = 0; |
oscargao | 0:941787ae3c86 | 26 | float water = 0.0; |
oscargao | 0:941787ae3c86 | 27 | float light = 0.0; |
oscargao | 0:941787ae3c86 | 28 | float moist = 0.0; |
oscargao | 0:941787ae3c86 | 29 | speaker.period(1.0/2000.0); |
oscargao | 1:5ceaf94b79e4 | 30 | |
oscargao | 1:5ceaf94b79e4 | 31 | button.attach_deasserted(&Button_Callback); |
oscargao | 1:5ceaf94b79e4 | 32 | button.setSampleFrequency(); |
oscargao | 0:941787ae3c86 | 33 | |
oscargao | 0:941787ae3c86 | 34 | while(1) { |
oscargao | 0:941787ae3c86 | 35 | water = waterSensor.read(); |
oscargao | 0:941787ae3c86 | 36 | moist = moistureSensor.read(); |
oscargao | 0:941787ae3c86 | 37 | light = lightSensor.read(); |
oscargao | 1:5ceaf94b79e4 | 38 | uLCD.cls(); |
oscargao | 1:5ceaf94b79e4 | 39 | uLCD.printf("%d:\n\r",counting); |
oscargao | 1:5ceaf94b79e4 | 40 | uLCD.printf("%f water\n\r",water); |
oscargao | 1:5ceaf94b79e4 | 41 | uLCD.printf("%f moist\n\r",moist); |
oscargao | 1:5ceaf94b79e4 | 42 | uLCD.printf("%f light\n\r",light); |
oscargao | 0:941787ae3c86 | 43 | counting++; |
oscargao | 0:941787ae3c86 | 44 | |
oscargao | 1:5ceaf94b79e4 | 45 | if (light<0.1){led.write(1-light);} |
oscargao | 1:5ceaf94b79e4 | 46 | else{led = 0;} |
oscargao | 1:5ceaf94b79e4 | 47 | |
oscargao | 0:941787ae3c86 | 48 | wait(1); |
oscargao | 0:941787ae3c86 | 49 | } |
oscargao | 0:941787ae3c86 | 50 | } |