School project.

Dependencies:   Timezone NTPClient BSP_DISCO_F746NG Grove_temperature

Committer:
tuxx0046
Date:
Fri Jan 15 09:27:26 2021 +0000
Revision:
10:137cf2c92871
Parent:
9:fd1f07a4a0ff
Child:
11:f3e516401328
Add serial communication service functions.; Major changes to comments.; Minor fixes to code to clear buffer in console when typing etc.;

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