School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
main.cpp@6:aecab8e3acad, 2021-01-14 (annotated)
- Committer:
- tuxx0046
- Date:
- Thu Jan 14 12:14:51 2021 +0000
- Revision:
- 6:aecab8e3acad
- Parent:
- 4:1a12157689a7
- Child:
- 7:b80c993f4db5
Added LED function that controls blinking rate of LED.; Added light sensor function to convert light sensor reading to percent.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuxx0046 | 1:1ee11539cc43 | 1 | /** |
tuxx0046 | 0:ed4063a0a4d5 | 2 | @file main.cpp |
tuxx0046 | 0:ed4063a0a4d5 | 3 | @brief Light Control System to automatically dimmer or increase light levels depending on registered light intensity. |
tuxx0046 | 6:aecab8e3acad | 4 | Made for: |
tuxx0046 | 6:aecab8e3acad | 5 | STM32F746G-DISCOVERY |
tuxx0046 | 6:aecab8e3acad | 6 | Grove Base Shield v2.1 |
tuxx0046 | 6:aecab8e3acad | 7 | Grove Light Sensor v1.2 |
tuxx0046 | 6:aecab8e3acad | 8 | Grove Rotary Angle Sensor v1.2 |
tuxx0046 | 6:aecab8e3acad | 9 | Grove LED Socket Kit v1.5 |
tuxx0046 | 6:aecab8e3acad | 10 | Grove LED diode |
tuxx0046 | 6:aecab8e3acad | 11 | Grove Button v1.2 |
tuxx0046 | 6:aecab8e3acad | 12 | |
tuxx0046 | 0:ed4063a0a4d5 | 13 | @author Tu Tri Huynh |
tuxx0046 | 0:ed4063a0a4d5 | 14 | @date 1/13/2021 |
tuxx0046 | 0:ed4063a0a4d5 | 15 | */ |
tuxx0046 | 0:ed4063a0a4d5 | 16 | |
tuxx0046 | 0:ed4063a0a4d5 | 17 | #include "mbed.h" |
tuxx0046 | 6:aecab8e3acad | 18 | |
tuxx0046 | 6:aecab8e3acad | 19 | AnalogIn light_sensor(A0); |
tuxx0046 | 6:aecab8e3acad | 20 | PwmOut led(D3); |
tuxx0046 | 6:aecab8e3acad | 21 | |
tuxx0046 | 0:ed4063a0a4d5 | 22 | char building[31]; |
tuxx0046 | 0:ed4063a0a4d5 | 23 | char room[31]; |
tuxx0046 | 0:ed4063a0a4d5 | 24 | |
tuxx0046 | 2:90d31841523a | 25 | /// Used to test the controller and make sure that it functions |
tuxx0046 | 6:aecab8e3acad | 26 | /** DigitalOut myled(LED1); */ |
tuxx0046 | 0:ed4063a0a4d5 | 27 | |
tuxx0046 | 3:02e7aac23ff9 | 28 | #include "setup_functions.h" |
tuxx0046 | 4:1a12157689a7 | 29 | #include "lcd_functions.h" |
tuxx0046 | 6:aecab8e3acad | 30 | #include "led_functions.h" |
tuxx0046 | 0:ed4063a0a4d5 | 31 | |
tuxx0046 | 0:ed4063a0a4d5 | 32 | int main(){ |
tuxx0046 | 0:ed4063a0a4d5 | 33 | /* |
tuxx0046 | 4:1a12157689a7 | 34 | lcd_initialize(); |
tuxx0046 | 4:1a12157689a7 | 35 | lcd_show_setup_screen(); |
tuxx0046 | 6:aecab8e3acad | 36 | setup_run_setup();*/ |
tuxx0046 | 6:aecab8e3acad | 37 | |
tuxx0046 | 6:aecab8e3acad | 38 | float light_sensor_reading; |
tuxx0046 | 2:90d31841523a | 39 | while(1) |
tuxx0046 | 2:90d31841523a | 40 | { |
tuxx0046 | 6:aecab8e3acad | 41 | light_sensor_reading = light_sensor.read(); |
tuxx0046 | 6:aecab8e3acad | 42 | printf("%1.2f\n", light_sensor_reading); |
tuxx0046 | 6:aecab8e3acad | 43 | led_set_blink_rate(light_sensor_reading); |
tuxx0046 | 6:aecab8e3acad | 44 | wait_us(1000000); |
tuxx0046 | 4:1a12157689a7 | 45 | |
tuxx0046 | 2:90d31841523a | 46 | /** 01/13/2021 Used to test the controller and make sure that it functions.*/ |
tuxx0046 | 2:90d31841523a | 47 | /** |
tuxx0046 | 2:90d31841523a | 48 | printf("This is a test.\n"); |
tuxx0046 | 2:90d31841523a | 49 | myled = 1; |
tuxx0046 | 2:90d31841523a | 50 | wait_us(1000000); |
tuxx0046 | 2:90d31841523a | 51 | myled = 0; |
tuxx0046 | 2:90d31841523a | 52 | wait_us(1000000); |
tuxx0046 | 2:90d31841523a | 53 | */ |
tuxx0046 | 2:90d31841523a | 54 | } |
tuxx0046 | 6:aecab8e3acad | 55 | |
tuxx0046 | 6:aecab8e3acad | 56 | /** |
tuxx0046 | 6:aecab8e3acad | 57 | printf("Mbed OS version: %d,%d,%d\n\n",MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); |
tuxx0046 | 6:aecab8e3acad | 58 | */ |
tuxx0046 | 0:ed4063a0a4d5 | 59 | } |