School project.

Dependencies:   Timezone NTPClient BSP_DISCO_F746NG Grove_temperature

Committer:
tuxx0046
Date:
Mon Jan 18 13:39:58 2021 +0000
Revision:
13:41debc0b9063
Parent:
12:50b76050d163
Child:
14:3ac7c08dbc52
Temperature reading functionality added.; Button functionality added, so a button press will change temperature from celsius to fahrenheit.; Comments fixed and added.

Who changed what in which revision?

UserRevisionLine numberNew 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 12:50b76050d163 20 Grove Temperature Sensor v1.2
tuxx0046 10:137cf2c92871 21 ******************************************************************************
tuxx0046 0:ed4063a0a4d5 22 */
tuxx0046 0:ed4063a0a4d5 23
tuxx0046 0:ed4063a0a4d5 24 #include "mbed.h"
tuxx0046 11:f3e516401328 25 #include "Grove_temperature.h"
tuxx0046 6:aecab8e3acad 26
tuxx0046 6:aecab8e3acad 27 AnalogIn light_sensor(A0);
tuxx0046 9:fd1f07a4a0ff 28 AnalogIn rotary(A1);
tuxx0046 13:41debc0b9063 29 DigitalIn button(D5);
tuxx0046 6:aecab8e3acad 30 PwmOut led(D3);
tuxx0046 11:f3e516401328 31 Grove_temperature temp(A2);
tuxx0046 0:ed4063a0a4d5 32 char building[31];
tuxx0046 0:ed4063a0a4d5 33 char room[31];
tuxx0046 13:41debc0b9063 34 float light_sensor_reading;
tuxx0046 13:41debc0b9063 35 float rotary_reading;
tuxx0046 13:41debc0b9063 36 int light_intensity;
tuxx0046 13:41debc0b9063 37 int rotary_setting;
tuxx0046 0:ed4063a0a4d5 38
tuxx0046 13:41debc0b9063 39 DigitalOut myled(LED1);
tuxx0046 0:ed4063a0a4d5 40
tuxx0046 9:fd1f07a4a0ff 41 #include "helper_functions.h"
tuxx0046 3:02e7aac23ff9 42 #include "setup_functions.h"
tuxx0046 4:1a12157689a7 43 #include "lcd_functions.h"
tuxx0046 6:aecab8e3acad 44 #include "led_functions.h"
tuxx0046 9:fd1f07a4a0ff 45 #include "rotary_functions.h"
tuxx0046 10:137cf2c92871 46 #include "sc_functions.h"
tuxx0046 13:41debc0b9063 47 #include "button_functions.h"
tuxx0046 9:fd1f07a4a0ff 48
tuxx0046 0:ed4063a0a4d5 49
tuxx0046 13:41debc0b9063 50 void update_readings()
tuxx0046 13:41debc0b9063 51 {
tuxx0046 13:41debc0b9063 52 light_sensor_reading = light_sensor.read();
tuxx0046 13:41debc0b9063 53 light_intensity = helper_get_sensor_read_in_percent(light_sensor_reading);
tuxx0046 13:41debc0b9063 54 rotary_reading = rotary.read();
tuxx0046 13:41debc0b9063 55 rotary_setting = helper_get_sensor_read_in_percent(rotary_reading);
tuxx0046 13:41debc0b9063 56 }
tuxx0046 13:41debc0b9063 57
tuxx0046 0:ed4063a0a4d5 58 int main(){
tuxx0046 10:137cf2c92871 59
tuxx0046 4:1a12157689a7 60 lcd_initialize();
tuxx0046 4:1a12157689a7 61 lcd_show_setup_screen();
tuxx0046 13:41debc0b9063 62 //setup_run_setup();
tuxx0046 13:41debc0b9063 63
tuxx0046 13:41debc0b9063 64 bool is_fahrenheit = false;
tuxx0046 13:41debc0b9063 65
tuxx0046 13:41debc0b9063 66 lcd_upper_right();
tuxx0046 10:137cf2c92871 67
tuxx0046 10:137cf2c92871 68 Thread serial_communication;
tuxx0046 13:41debc0b9063 69 //serial_communication.start(&sc_run_service);
tuxx0046 6:aecab8e3acad 70
tuxx0046 13:41debc0b9063 71 lcd_lower_right();
tuxx0046 13:41debc0b9063 72 lcd_upper_right();
tuxx0046 13:41debc0b9063 73 lcd_lower_left();
tuxx0046 13:41debc0b9063 74 lcd_update_lower_left(building, room);
tuxx0046 2:90d31841523a 75 while(1)
tuxx0046 2:90d31841523a 76 {
tuxx0046 13:41debc0b9063 77 button_switch_temp_unit(button, is_fahrenheit);
tuxx0046 13:41debc0b9063 78
tuxx0046 13:41debc0b9063 79 lcd_update_lower_right(temp.getTemperature(), is_fahrenheit);
tuxx0046 13:41debc0b9063 80 wait_us(500000);
tuxx0046 13:41debc0b9063 81
tuxx0046 11:f3e516401328 82 /** Code for testing temperature sensor
tuxx0046 11:f3e516401328 83 1/18/2021 - Working
tuxx0046 11:f3e516401328 84 */
tuxx0046 11:f3e516401328 85 /**
tuxx0046 11:f3e516401328 86 printf("Current temperatur is: %2.2f\n", temp.getTemperature());
tuxx0046 11:f3e516401328 87 wait_us(1000000);
tuxx0046 11:f3e516401328 88 */
tuxx0046 11:f3e516401328 89
tuxx0046 9:fd1f07a4a0ff 90 /** Code for testing that the rotary can control the LED light blinking
tuxx0046 9:fd1f07a4a0ff 91 1/14/2021 Working
tuxx0046 9:fd1f07a4a0ff 92 */
tuxx0046 11:f3e516401328 93 /**
tuxx0046 9:fd1f07a4a0ff 94 rotary_reading = rotary_reverse_read(rotary);
tuxx0046 9:fd1f07a4a0ff 95 printf("%1.2f\n",rotary_reading);
tuxx0046 9:fd1f07a4a0ff 96 led_set_blink_rate(rotary_reading);
tuxx0046 9:fd1f07a4a0ff 97 wait_us(2000000);
tuxx0046 10:137cf2c92871 98 */
tuxx0046 9:fd1f07a4a0ff 99
tuxx0046 9:fd1f07a4a0ff 100 /** Code for testing if rotary has been turned or not
tuxx0046 9:fd1f07a4a0ff 101 1/14/2021 Working
tuxx0046 9:fd1f07a4a0ff 102 */
tuxx0046 9:fd1f07a4a0ff 103 /**
tuxx0046 9:fd1f07a4a0ff 104 if (rotary_is_on(rotary))
tuxx0046 9:fd1f07a4a0ff 105 {
tuxx0046 9:fd1f07a4a0ff 106 printf("Rotary is on\n");
tuxx0046 9:fd1f07a4a0ff 107 }
tuxx0046 9:fd1f07a4a0ff 108 else
tuxx0046 9:fd1f07a4a0ff 109 {
tuxx0046 9:fd1f07a4a0ff 110 printf("Rotary is off\n");
tuxx0046 9:fd1f07a4a0ff 111 }
tuxx0046 9:fd1f07a4a0ff 112 wait_us(1000000);
tuxx0046 9:fd1f07a4a0ff 113 */
tuxx0046 9:fd1f07a4a0ff 114
tuxx0046 9:fd1f07a4a0ff 115 /** Code for testing sensor readings
tuxx0046 9:fd1f07a4a0ff 116 1/14/2021 Working
tuxx0046 9:fd1f07a4a0ff 117 */
tuxx0046 9:fd1f07a4a0ff 118 /**
tuxx0046 6:aecab8e3acad 119 light_sensor_reading = light_sensor.read();
tuxx0046 9:fd1f07a4a0ff 120 rotary_reading = rotary.read();
tuxx0046 9:fd1f07a4a0ff 121 printf("Light intensity: %i%%\n", helper_get_sensor_read_in_percent(light_sensor_reading));
tuxx0046 9:fd1f07a4a0ff 122 printf("Rotary turned: %i%%\n", helper_get_sensor_read_in_percent(rotary_reading));
tuxx0046 6:aecab8e3acad 123 led_set_blink_rate(light_sensor_reading);
tuxx0046 6:aecab8e3acad 124 wait_us(1000000);
tuxx0046 9:fd1f07a4a0ff 125 */
tuxx0046 4:1a12157689a7 126
tuxx0046 9:fd1f07a4a0ff 127 /** 1/13/2021 Used to test the controller and make sure that it functions.*/
tuxx0046 2:90d31841523a 128 /**
tuxx0046 2:90d31841523a 129 printf("This is a test.\n");
tuxx0046 2:90d31841523a 130 myled = 1;
tuxx0046 2:90d31841523a 131 wait_us(1000000);
tuxx0046 2:90d31841523a 132 myled = 0;
tuxx0046 2:90d31841523a 133 wait_us(1000000);
tuxx0046 2:90d31841523a 134 */
tuxx0046 2:90d31841523a 135 }
tuxx0046 6:aecab8e3acad 136
tuxx0046 6:aecab8e3acad 137 /**
tuxx0046 6:aecab8e3acad 138 printf("Mbed OS version: %d,%d,%d\n\n",MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
tuxx0046 6:aecab8e3acad 139 */
tuxx0046 0:ed4063a0a4d5 140 }