School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
main.cpp@20:9d4450357ce7, 2021-01-21 (annotated)
- Committer:
- tuxx0046
- Date:
- Thu Jan 21 12:43:03 2021 +0000
- Revision:
- 20:9d4450357ce7
- Parent:
- 19:a23c25da398e
Updated libraries used section in comments in main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuxx0046 | 1:1ee11539cc43 | 1 | /** |
tuxx0046 | 10:137cf2c92871 | 2 | ****************************************************************************** |
tuxx0046 | 10:137cf2c92871 | 3 | @file main.cpp |
tuxx0046 | 10:137cf2c92871 | 4 | @author Tu Tri Huynh |
tuxx0046 | 10:137cf2c92871 | 5 | @date January 13, 2021 |
tuxx0046 | 10:137cf2c92871 | 6 | @brief Light Control System to automatically dimmer or increase light levels |
tuxx0046 | 10:137cf2c92871 | 7 | @section Libraries used |
tuxx0046 | 11:f3e516401328 | 8 | mbed-os version 6.6.0 |
tuxx0046 | 10:137cf2c92871 | 9 | BSP_DISCO_F746NG, revision 13:85dbcff by Team ST |
tuxx0046 | 11:f3e516401328 | 10 | Grove_temperature, v1.0.0 by Toyomasa Watarai |
tuxx0046 | 19:a23c25da398e | 11 | NTPClient, revision 0:9282d46 by Zoltan Hudak |
tuxx0046 | 19:a23c25da398e | 12 | Timezone, revision 0:38a95c8, originally by Jack Christensen and ported by Zoltan Hudak |
tuxx0046 | 10:137cf2c92871 | 13 | |
tuxx0046 | 20:9d4450357ce7 | 14 | @section Recommended hardware to run the program |
tuxx0046 | 10:137cf2c92871 | 15 | STM32F746G-DISCOVERY |
tuxx0046 | 10:137cf2c92871 | 16 | Grove Base Shield v2.1 |
tuxx0046 | 10:137cf2c92871 | 17 | Grove Light Sensor v1.2 |
tuxx0046 | 10:137cf2c92871 | 18 | Grove Rotary Angle Sensor v1.2 |
tuxx0046 | 10:137cf2c92871 | 19 | Grove LED Socket Kit v1.5 |
tuxx0046 | 10:137cf2c92871 | 20 | Grove LED diode |
tuxx0046 | 10:137cf2c92871 | 21 | Grove Button v1.2 |
tuxx0046 | 12:50b76050d163 | 22 | Grove Temperature Sensor v1.2 |
tuxx0046 | 10:137cf2c92871 | 23 | ****************************************************************************** |
tuxx0046 | 0:ed4063a0a4d5 | 24 | */ |
tuxx0046 | 0:ed4063a0a4d5 | 25 | |
tuxx0046 | 0:ed4063a0a4d5 | 26 | #include "mbed.h" |
tuxx0046 | 11:f3e516401328 | 27 | #include "Grove_temperature.h" |
tuxx0046 | 17:01ebfd8ab87a | 28 | #include "stm32746g_discovery_lcd.h" |
tuxx0046 | 17:01ebfd8ab87a | 29 | #include "EthernetInterface.h" |
tuxx0046 | 17:01ebfd8ab87a | 30 | #include "NTPClient.h" |
tuxx0046 | 6:aecab8e3acad | 31 | |
tuxx0046 | 6:aecab8e3acad | 32 | AnalogIn light_sensor(A0); |
tuxx0046 | 9:fd1f07a4a0ff | 33 | AnalogIn rotary(A1); |
tuxx0046 | 13:41debc0b9063 | 34 | DigitalIn button(D5); |
tuxx0046 | 6:aecab8e3acad | 35 | PwmOut led(D3); |
tuxx0046 | 11:f3e516401328 | 36 | Grove_temperature temp(A2); |
tuxx0046 | 17:01ebfd8ab87a | 37 | EthernetInterface eth; |
tuxx0046 | 17:01ebfd8ab87a | 38 | NTPClient ntp(eth); |
tuxx0046 | 15:638e65c37d58 | 39 | /// Name of building to install the unit |
tuxx0046 | 0:ed4063a0a4d5 | 40 | char building[31]; |
tuxx0046 | 15:638e65c37d58 | 41 | /// Name of room to install the unit |
tuxx0046 | 0:ed4063a0a4d5 | 42 | char room[31]; |
tuxx0046 | 15:638e65c37d58 | 43 | |
tuxx0046 | 13:41debc0b9063 | 44 | float light_sensor_reading; |
tuxx0046 | 13:41debc0b9063 | 45 | float rotary_reading; |
tuxx0046 | 15:638e65c37d58 | 46 | /// The percentage of light registered |
tuxx0046 | 13:41debc0b9063 | 47 | int light_intensity; |
tuxx0046 | 15:638e65c37d58 | 48 | /// The percentage of rotary turned |
tuxx0046 | 13:41debc0b9063 | 49 | int rotary_setting; |
tuxx0046 | 0:ed4063a0a4d5 | 50 | |
tuxx0046 | 16:296d68305630 | 51 | /// Used to determine if change in temperature has occured when new readings are performed |
tuxx0046 | 15:638e65c37d58 | 52 | int current_temp; |
tuxx0046 | 16:296d68305630 | 53 | /// Used to check if temperature unit should be switched or not |
tuxx0046 | 16:296d68305630 | 54 | bool switch_temp; |
tuxx0046 | 15:638e65c37d58 | 55 | bool is_fahrenheit = false; |
tuxx0046 | 15:638e65c37d58 | 56 | |
tuxx0046 | 16:296d68305630 | 57 | |
tuxx0046 | 16:296d68305630 | 58 | /*DigitalOut myled(LED1);*/ |
tuxx0046 | 0:ed4063a0a4d5 | 59 | |
tuxx0046 | 9:fd1f07a4a0ff | 60 | #include "helper_functions.h" |
tuxx0046 | 3:02e7aac23ff9 | 61 | #include "setup_functions.h" |
tuxx0046 | 4:1a12157689a7 | 62 | #include "lcd_functions.h" |
tuxx0046 | 6:aecab8e3acad | 63 | #include "led_functions.h" |
tuxx0046 | 9:fd1f07a4a0ff | 64 | #include "rotary_functions.h" |
tuxx0046 | 10:137cf2c92871 | 65 | #include "sc_functions.h" |
tuxx0046 | 13:41debc0b9063 | 66 | #include "button_functions.h" |
tuxx0046 | 14:3ac7c08dbc52 | 67 | #include "main_functions.h" |
tuxx0046 | 17:01ebfd8ab87a | 68 | #include "time_functions.h" |
tuxx0046 | 0:ed4063a0a4d5 | 69 | |
tuxx0046 | 13:41debc0b9063 | 70 | |
tuxx0046 | 17:01ebfd8ab87a | 71 | int main() |
tuxx0046 | 17:01ebfd8ab87a | 72 | { |
tuxx0046 | 16:296d68305630 | 73 | main_run_setup(); |
tuxx0046 | 16:296d68305630 | 74 | main_run_main_screen(); |
tuxx0046 | 17:01ebfd8ab87a | 75 | |
tuxx0046 | 10:137cf2c92871 | 76 | Thread serial_communication; |
tuxx0046 | 14:3ac7c08dbc52 | 77 | serial_communication.start(&sc_run_service); |
tuxx0046 | 16:296d68305630 | 78 | |
tuxx0046 | 17:01ebfd8ab87a | 79 | Thread clock; |
tuxx0046 | 17:01ebfd8ab87a | 80 | clock.start(&time_update_current_time); |
tuxx0046 | 17:01ebfd8ab87a | 81 | |
tuxx0046 | 16:296d68305630 | 82 | Thread button_check; |
tuxx0046 | 16:296d68305630 | 83 | button_check.start(&main_run_button_check); |
tuxx0046 | 17:01ebfd8ab87a | 84 | |
tuxx0046 | 2:90d31841523a | 85 | while(1) |
tuxx0046 | 2:90d31841523a | 86 | { |
tuxx0046 | 16:296d68305630 | 87 | main_update_readings(); |
tuxx0046 | 16:296d68305630 | 88 | main_check_light_control(); |
tuxx0046 | 15:638e65c37d58 | 89 | |
tuxx0046 | 14:3ac7c08dbc52 | 90 | wait_us(1000000); |
tuxx0046 | 17:01ebfd8ab87a | 91 | |
tuxx0046 | 11:f3e516401328 | 92 | /** Code for testing temperature sensor |
tuxx0046 | 11:f3e516401328 | 93 | 1/18/2021 - Working |
tuxx0046 | 11:f3e516401328 | 94 | */ |
tuxx0046 | 11:f3e516401328 | 95 | /** |
tuxx0046 | 11:f3e516401328 | 96 | printf("Current temperatur is: %2.2f\n", temp.getTemperature()); |
tuxx0046 | 11:f3e516401328 | 97 | wait_us(1000000); |
tuxx0046 | 11:f3e516401328 | 98 | */ |
tuxx0046 | 14:3ac7c08dbc52 | 99 | |
tuxx0046 | 14:3ac7c08dbc52 | 100 | /** Code for testing that the rotary can control the LED light blinking |
tuxx0046 | 9:fd1f07a4a0ff | 101 | 1/14/2021 Working |
tuxx0046 | 9:fd1f07a4a0ff | 102 | */ |
tuxx0046 | 11:f3e516401328 | 103 | /** |
tuxx0046 | 9:fd1f07a4a0ff | 104 | rotary_reading = rotary_reverse_read(rotary); |
tuxx0046 | 9:fd1f07a4a0ff | 105 | printf("%1.2f\n",rotary_reading); |
tuxx0046 | 9:fd1f07a4a0ff | 106 | led_set_blink_rate(rotary_reading); |
tuxx0046 | 9:fd1f07a4a0ff | 107 | wait_us(2000000); |
tuxx0046 | 10:137cf2c92871 | 108 | */ |
tuxx0046 | 14:3ac7c08dbc52 | 109 | |
tuxx0046 | 14:3ac7c08dbc52 | 110 | /** Code for testing if rotary has been turned or not |
tuxx0046 | 9:fd1f07a4a0ff | 111 | 1/14/2021 Working |
tuxx0046 | 9:fd1f07a4a0ff | 112 | */ |
tuxx0046 | 9:fd1f07a4a0ff | 113 | /** |
tuxx0046 | 9:fd1f07a4a0ff | 114 | if (rotary_is_on(rotary)) |
tuxx0046 | 9:fd1f07a4a0ff | 115 | { |
tuxx0046 | 9:fd1f07a4a0ff | 116 | printf("Rotary is on\n"); |
tuxx0046 | 9:fd1f07a4a0ff | 117 | } |
tuxx0046 | 9:fd1f07a4a0ff | 118 | else |
tuxx0046 | 9:fd1f07a4a0ff | 119 | { |
tuxx0046 | 9:fd1f07a4a0ff | 120 | printf("Rotary is off\n"); |
tuxx0046 | 9:fd1f07a4a0ff | 121 | } |
tuxx0046 | 9:fd1f07a4a0ff | 122 | wait_us(1000000); |
tuxx0046 | 9:fd1f07a4a0ff | 123 | */ |
tuxx0046 | 14:3ac7c08dbc52 | 124 | |
tuxx0046 | 9:fd1f07a4a0ff | 125 | /** Code for testing sensor readings |
tuxx0046 | 14:3ac7c08dbc52 | 126 | 1/14/2021 Working |
tuxx0046 | 9:fd1f07a4a0ff | 127 | */ |
tuxx0046 | 9:fd1f07a4a0ff | 128 | /** |
tuxx0046 | 6:aecab8e3acad | 129 | light_sensor_reading = light_sensor.read(); |
tuxx0046 | 9:fd1f07a4a0ff | 130 | rotary_reading = rotary.read(); |
tuxx0046 | 9:fd1f07a4a0ff | 131 | printf("Light intensity: %i%%\n", helper_get_sensor_read_in_percent(light_sensor_reading)); |
tuxx0046 | 9:fd1f07a4a0ff | 132 | printf("Rotary turned: %i%%\n", helper_get_sensor_read_in_percent(rotary_reading)); |
tuxx0046 | 6:aecab8e3acad | 133 | led_set_blink_rate(light_sensor_reading); |
tuxx0046 | 6:aecab8e3acad | 134 | wait_us(1000000); |
tuxx0046 | 9:fd1f07a4a0ff | 135 | */ |
tuxx0046 | 14:3ac7c08dbc52 | 136 | |
tuxx0046 | 9:fd1f07a4a0ff | 137 | /** 1/13/2021 Used to test the controller and make sure that it functions.*/ |
tuxx0046 | 2:90d31841523a | 138 | /** |
tuxx0046 | 2:90d31841523a | 139 | printf("This is a test.\n"); |
tuxx0046 | 2:90d31841523a | 140 | myled = 1; |
tuxx0046 | 2:90d31841523a | 141 | wait_us(1000000); |
tuxx0046 | 14:3ac7c08dbc52 | 142 | myled = 0; |
tuxx0046 | 2:90d31841523a | 143 | wait_us(1000000); |
tuxx0046 | 2:90d31841523a | 144 | */ |
tuxx0046 | 6:aecab8e3acad | 145 | |
tuxx0046 | 14:3ac7c08dbc52 | 146 | /** |
tuxx0046 | 14:3ac7c08dbc52 | 147 | printf("Mbed OS version: %d,%d,%d\n\n",MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); |
tuxx0046 | 14:3ac7c08dbc52 | 148 | */ |
tuxx0046 | 14:3ac7c08dbc52 | 149 | } |
tuxx0046 | 0:ed4063a0a4d5 | 150 | } |