School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
main.cpp@11:f3e516401328, 2021-01-18 (annotated)
- Committer:
- tuxx0046
- Date:
- Mon Jan 18 07:40:54 2021 +0000
- Revision:
- 11:f3e516401328
- Parent:
- 10:137cf2c92871
- Child:
- 12:50b76050d163
Grove_temperature library added and tested.
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 | 10:137cf2c92871 | 11 | |
tuxx0046 | 10:137cf2c92871 | 12 | @section Recommended hardware |
tuxx0046 | 10:137cf2c92871 | 13 | STM32F746G-DISCOVERY |
tuxx0046 | 10:137cf2c92871 | 14 | Grove Base Shield v2.1 |
tuxx0046 | 10:137cf2c92871 | 15 | Grove Light Sensor v1.2 |
tuxx0046 | 10:137cf2c92871 | 16 | Grove Rotary Angle Sensor v1.2 |
tuxx0046 | 10:137cf2c92871 | 17 | Grove LED Socket Kit v1.5 |
tuxx0046 | 10:137cf2c92871 | 18 | Grove LED diode |
tuxx0046 | 10:137cf2c92871 | 19 | Grove Button v1.2 |
tuxx0046 | 10:137cf2c92871 | 20 | ****************************************************************************** |
tuxx0046 | 0:ed4063a0a4d5 | 21 | */ |
tuxx0046 | 0:ed4063a0a4d5 | 22 | |
tuxx0046 | 0:ed4063a0a4d5 | 23 | #include "mbed.h" |
tuxx0046 | 11:f3e516401328 | 24 | #include "Grove_temperature.h" |
tuxx0046 | 6:aecab8e3acad | 25 | |
tuxx0046 | 6:aecab8e3acad | 26 | AnalogIn light_sensor(A0); |
tuxx0046 | 9:fd1f07a4a0ff | 27 | AnalogIn rotary(A1); |
tuxx0046 | 6:aecab8e3acad | 28 | PwmOut led(D3); |
tuxx0046 | 11:f3e516401328 | 29 | Grove_temperature temp(A2); |
tuxx0046 | 0:ed4063a0a4d5 | 30 | char building[31]; |
tuxx0046 | 0:ed4063a0a4d5 | 31 | char room[31]; |
tuxx0046 | 0:ed4063a0a4d5 | 32 | |
tuxx0046 | 6:aecab8e3acad | 33 | /** DigitalOut myled(LED1); */ |
tuxx0046 | 0:ed4063a0a4d5 | 34 | |
tuxx0046 | 9:fd1f07a4a0ff | 35 | #include "helper_functions.h" |
tuxx0046 | 3:02e7aac23ff9 | 36 | #include "setup_functions.h" |
tuxx0046 | 4:1a12157689a7 | 37 | #include "lcd_functions.h" |
tuxx0046 | 6:aecab8e3acad | 38 | #include "led_functions.h" |
tuxx0046 | 9:fd1f07a4a0ff | 39 | #include "rotary_functions.h" |
tuxx0046 | 10:137cf2c92871 | 40 | #include "sc_functions.h" |
tuxx0046 | 9:fd1f07a4a0ff | 41 | |
tuxx0046 | 0:ed4063a0a4d5 | 42 | |
tuxx0046 | 0:ed4063a0a4d5 | 43 | int main(){ |
tuxx0046 | 10:137cf2c92871 | 44 | |
tuxx0046 | 4:1a12157689a7 | 45 | lcd_initialize(); |
tuxx0046 | 4:1a12157689a7 | 46 | lcd_show_setup_screen(); |
tuxx0046 | 10:137cf2c92871 | 47 | setup_run_setup(); |
tuxx0046 | 10:137cf2c92871 | 48 | |
tuxx0046 | 10:137cf2c92871 | 49 | Thread serial_communication; |
tuxx0046 | 10:137cf2c92871 | 50 | serial_communication.start(&sc_run_service); |
tuxx0046 | 6:aecab8e3acad | 51 | |
tuxx0046 | 6:aecab8e3acad | 52 | float light_sensor_reading; |
tuxx0046 | 9:fd1f07a4a0ff | 53 | float rotary_reading; |
tuxx0046 | 2:90d31841523a | 54 | while(1) |
tuxx0046 | 2:90d31841523a | 55 | { |
tuxx0046 | 11:f3e516401328 | 56 | /** Code for testing temperature sensor |
tuxx0046 | 11:f3e516401328 | 57 | 1/18/2021 - Working |
tuxx0046 | 11:f3e516401328 | 58 | */ |
tuxx0046 | 11:f3e516401328 | 59 | /** |
tuxx0046 | 11:f3e516401328 | 60 | printf("Current temperatur is: %2.2f\n", temp.getTemperature()); |
tuxx0046 | 11:f3e516401328 | 61 | wait_us(1000000); |
tuxx0046 | 11:f3e516401328 | 62 | */ |
tuxx0046 | 11:f3e516401328 | 63 | |
tuxx0046 | 9:fd1f07a4a0ff | 64 | /** Code for testing that the rotary can control the LED light blinking |
tuxx0046 | 9:fd1f07a4a0ff | 65 | 1/14/2021 Working |
tuxx0046 | 9:fd1f07a4a0ff | 66 | */ |
tuxx0046 | 11:f3e516401328 | 67 | /** |
tuxx0046 | 9:fd1f07a4a0ff | 68 | rotary_reading = rotary_reverse_read(rotary); |
tuxx0046 | 9:fd1f07a4a0ff | 69 | printf("%1.2f\n",rotary_reading); |
tuxx0046 | 9:fd1f07a4a0ff | 70 | led_set_blink_rate(rotary_reading); |
tuxx0046 | 9:fd1f07a4a0ff | 71 | wait_us(2000000); |
tuxx0046 | 10:137cf2c92871 | 72 | */ |
tuxx0046 | 9:fd1f07a4a0ff | 73 | |
tuxx0046 | 9:fd1f07a4a0ff | 74 | /** Code for testing if rotary has been turned or not |
tuxx0046 | 9:fd1f07a4a0ff | 75 | 1/14/2021 Working |
tuxx0046 | 9:fd1f07a4a0ff | 76 | */ |
tuxx0046 | 9:fd1f07a4a0ff | 77 | /** |
tuxx0046 | 9:fd1f07a4a0ff | 78 | if (rotary_is_on(rotary)) |
tuxx0046 | 9:fd1f07a4a0ff | 79 | { |
tuxx0046 | 9:fd1f07a4a0ff | 80 | printf("Rotary is on\n"); |
tuxx0046 | 9:fd1f07a4a0ff | 81 | } |
tuxx0046 | 9:fd1f07a4a0ff | 82 | else |
tuxx0046 | 9:fd1f07a4a0ff | 83 | { |
tuxx0046 | 9:fd1f07a4a0ff | 84 | printf("Rotary is off\n"); |
tuxx0046 | 9:fd1f07a4a0ff | 85 | } |
tuxx0046 | 9:fd1f07a4a0ff | 86 | wait_us(1000000); |
tuxx0046 | 9:fd1f07a4a0ff | 87 | */ |
tuxx0046 | 9:fd1f07a4a0ff | 88 | |
tuxx0046 | 9:fd1f07a4a0ff | 89 | /** Code for testing sensor readings |
tuxx0046 | 9:fd1f07a4a0ff | 90 | 1/14/2021 Working |
tuxx0046 | 9:fd1f07a4a0ff | 91 | */ |
tuxx0046 | 9:fd1f07a4a0ff | 92 | /** |
tuxx0046 | 6:aecab8e3acad | 93 | light_sensor_reading = light_sensor.read(); |
tuxx0046 | 9:fd1f07a4a0ff | 94 | rotary_reading = rotary.read(); |
tuxx0046 | 9:fd1f07a4a0ff | 95 | printf("Light intensity: %i%%\n", helper_get_sensor_read_in_percent(light_sensor_reading)); |
tuxx0046 | 9:fd1f07a4a0ff | 96 | printf("Rotary turned: %i%%\n", helper_get_sensor_read_in_percent(rotary_reading)); |
tuxx0046 | 6:aecab8e3acad | 97 | led_set_blink_rate(light_sensor_reading); |
tuxx0046 | 6:aecab8e3acad | 98 | wait_us(1000000); |
tuxx0046 | 9:fd1f07a4a0ff | 99 | */ |
tuxx0046 | 4:1a12157689a7 | 100 | |
tuxx0046 | 9:fd1f07a4a0ff | 101 | /** 1/13/2021 Used to test the controller and make sure that it functions.*/ |
tuxx0046 | 2:90d31841523a | 102 | /** |
tuxx0046 | 2:90d31841523a | 103 | printf("This is a test.\n"); |
tuxx0046 | 2:90d31841523a | 104 | myled = 1; |
tuxx0046 | 2:90d31841523a | 105 | wait_us(1000000); |
tuxx0046 | 2:90d31841523a | 106 | myled = 0; |
tuxx0046 | 2:90d31841523a | 107 | wait_us(1000000); |
tuxx0046 | 2:90d31841523a | 108 | */ |
tuxx0046 | 2:90d31841523a | 109 | } |
tuxx0046 | 6:aecab8e3acad | 110 | |
tuxx0046 | 6:aecab8e3acad | 111 | /** |
tuxx0046 | 6:aecab8e3acad | 112 | printf("Mbed OS version: %d,%d,%d\n\n",MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); |
tuxx0046 | 6:aecab8e3acad | 113 | */ |
tuxx0046 | 0:ed4063a0a4d5 | 114 | } |