Original Code Repo: https://os.mbed.com/users/priyank12p/code/Electronically-Connected-Intelligent-She/ Modified for Fall 2021 students.
Dependencies: mbed mbed-http ESP8266
main.cpp@9:607ee6e92552, 2019-11-27 (annotated)
- Committer:
- jakobjohn949
- Date:
- Wed Nov 27 20:53:24 2019 +0000
- Revision:
- 9:607ee6e92552
- Parent:
- 8:25138f7b9309
- Child:
- 10:e4b6bc6d9b07
delete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jakobjohn949 | 9:607ee6e92552 | 1 | /** |
jakobjohn949 | 9:607ee6e92552 | 2 | Group 1: Electronically Controlled Intelligent Systems |
jakobjohn949 | 9:607ee6e92552 | 3 | Team Members: Priyank Kalgaonkar, Sahil Kumar, Linknath Balasubramanian |
jakobjohn949 | 9:607ee6e92552 | 4 | ECE53301 - Final Project - Fall 2019 |
jakobjohn949 | 9:607ee6e92552 | 5 | **/ |
andcor02 | 8:25138f7b9309 | 6 | #include "mbed.h" |
andcor02 | 8:25138f7b9309 | 7 | #include "hcsr04.h" |
jakobjohn949 | 9:607ee6e92552 | 8 | |
jakobjohn949 | 9:607ee6e92552 | 9 | DigitalOut RLed(LED1); //Onboard Red LED = Warning |
jakobjohn949 | 9:607ee6e92552 | 10 | DigitalOut GLed(LED2); //Onboard Green LED = All OK |
jakobjohn949 | 9:607ee6e92552 | 11 | DigitalOut BLed(LED3); //Onboard Blue LED = Wifi Tx |
jakobjohn949 | 9:607ee6e92552 | 12 | HCSR04 usensor1(D8,D9); //ECHO Pin=D9, TRIG Pin=D8 |
andcor02 | 8:25138f7b9309 | 13 | |
jakobjohn949 | 9:607ee6e92552 | 14 | float distance; //distance=int for faster program exec. |
jakobjohn949 | 9:607ee6e92552 | 15 | float dist_remaining; |
jakobjohn949 | 9:607ee6e92552 | 16 | float dist_percent; |
jakobjohn949 | 9:607ee6e92552 | 17 | |
andcor02 | 8:25138f7b9309 | 18 | int main() |
andcor02 | 8:25138f7b9309 | 19 | { |
jakobjohn949 | 9:607ee6e92552 | 20 | int a = 30; |
andcor02 | 8:25138f7b9309 | 21 | while(1) { |
jakobjohn949 | 9:607ee6e92552 | 22 | usensor1.start(); |
jakobjohn949 | 9:607ee6e92552 | 23 | wait_ms(1000); |
jakobjohn949 | 9:607ee6e92552 | 24 | distance = usensor1.get_dist_cm(); |
jakobjohn949 | 9:607ee6e92552 | 25 | dist_remaining = a-distance; |
jakobjohn949 | 9:607ee6e92552 | 26 | dist_percent = (dist_remaining/30)*100; |
jakobjohn949 | 9:607ee6e92552 | 27 | |
jakobjohn949 | 9:607ee6e92552 | 28 | if (distance<30) { |
jakobjohn949 | 9:607ee6e92552 | 29 | RLed = 1; |
jakobjohn949 | 9:607ee6e92552 | 30 | BLed = 1; |
jakobjohn949 | 9:607ee6e92552 | 31 | GLed = 0; |
jakobjohn949 | 9:607ee6e92552 | 32 | printf("\rPercent remaining: %f\r", dist_percent); |
jakobjohn949 | 9:607ee6e92552 | 33 | } else { |
jakobjohn949 | 9:607ee6e92552 | 34 | GLed = 1; |
jakobjohn949 | 9:607ee6e92552 | 35 | BLed = 1; |
jakobjohn949 | 9:607ee6e92552 | 36 | RLed = 0; |
jakobjohn949 | 9:607ee6e92552 | 37 | printf("\rShelf Empty. Replenish Stock!\r"); |
jakobjohn949 | 9:607ee6e92552 | 38 | } |
andcor02 | 8:25138f7b9309 | 39 | } |
andcor02 | 8:25138f7b9309 | 40 | } |