School project.

Dependencies:   Timezone NTPClient BSP_DISCO_F746NG Grove_temperature

Committer:
tuxx0046
Date:
Thu Jan 14 14:07:01 2021 +0000
Revision:
9:fd1f07a4a0ff
Parent:
8:1a1e7cf7dcb6
Child:
10:137cf2c92871
Added rotary functions.; Fixed some minor things and comments.

Who changed what in which revision?

UserRevisionLine numberNew 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 9:fd1f07a4a0ff 20 AnalogIn rotary(A1);
tuxx0046 6:aecab8e3acad 21 PwmOut led(D3);
tuxx0046 6:aecab8e3acad 22
tuxx0046 0:ed4063a0a4d5 23 char building[31];
tuxx0046 0:ed4063a0a4d5 24 char room[31];
tuxx0046 0:ed4063a0a4d5 25
tuxx0046 2:90d31841523a 26 /// Used to test the controller and make sure that it functions
tuxx0046 6:aecab8e3acad 27 /** DigitalOut myled(LED1); */
tuxx0046 0:ed4063a0a4d5 28
tuxx0046 9:fd1f07a4a0ff 29 #include "helper_functions.h"
tuxx0046 3:02e7aac23ff9 30 #include "setup_functions.h"
tuxx0046 4:1a12157689a7 31 #include "lcd_functions.h"
tuxx0046 6:aecab8e3acad 32 #include "led_functions.h"
tuxx0046 9:fd1f07a4a0ff 33 #include "rotary_functions.h"
tuxx0046 9:fd1f07a4a0ff 34
tuxx0046 0:ed4063a0a4d5 35
tuxx0046 0:ed4063a0a4d5 36 int main(){
tuxx0046 0:ed4063a0a4d5 37 /*
tuxx0046 4:1a12157689a7 38 lcd_initialize();
tuxx0046 4:1a12157689a7 39 lcd_show_setup_screen();
tuxx0046 6:aecab8e3acad 40 setup_run_setup();*/
tuxx0046 6:aecab8e3acad 41
tuxx0046 6:aecab8e3acad 42 float light_sensor_reading;
tuxx0046 9:fd1f07a4a0ff 43 float rotary_reading;
tuxx0046 2:90d31841523a 44 while(1)
tuxx0046 2:90d31841523a 45 {
tuxx0046 9:fd1f07a4a0ff 46 /** Code for testing that the rotary can control the LED light blinking
tuxx0046 9:fd1f07a4a0ff 47 1/14/2021 Working
tuxx0046 9:fd1f07a4a0ff 48 */
tuxx0046 9:fd1f07a4a0ff 49 rotary_reading = rotary_reverse_read(rotary);
tuxx0046 9:fd1f07a4a0ff 50 printf("%1.2f\n",rotary_reading);
tuxx0046 9:fd1f07a4a0ff 51 led_set_blink_rate(rotary_reading);
tuxx0046 9:fd1f07a4a0ff 52 wait_us(2000000);
tuxx0046 9:fd1f07a4a0ff 53
tuxx0046 9:fd1f07a4a0ff 54 /** Code for testing if rotary has been turned or not
tuxx0046 9:fd1f07a4a0ff 55 1/14/2021 Working
tuxx0046 9:fd1f07a4a0ff 56 */
tuxx0046 9:fd1f07a4a0ff 57 /**
tuxx0046 9:fd1f07a4a0ff 58 if (rotary_is_on(rotary))
tuxx0046 9:fd1f07a4a0ff 59 {
tuxx0046 9:fd1f07a4a0ff 60 printf("Rotary is on\n");
tuxx0046 9:fd1f07a4a0ff 61 }
tuxx0046 9:fd1f07a4a0ff 62 else
tuxx0046 9:fd1f07a4a0ff 63 {
tuxx0046 9:fd1f07a4a0ff 64 printf("Rotary is off\n");
tuxx0046 9:fd1f07a4a0ff 65 }
tuxx0046 9:fd1f07a4a0ff 66 wait_us(1000000);
tuxx0046 9:fd1f07a4a0ff 67 */
tuxx0046 9:fd1f07a4a0ff 68
tuxx0046 9:fd1f07a4a0ff 69 /** Code for testing sensor readings
tuxx0046 9:fd1f07a4a0ff 70 1/14/2021 Working
tuxx0046 9:fd1f07a4a0ff 71 */
tuxx0046 9:fd1f07a4a0ff 72 /**
tuxx0046 6:aecab8e3acad 73 light_sensor_reading = light_sensor.read();
tuxx0046 9:fd1f07a4a0ff 74 rotary_reading = rotary.read();
tuxx0046 9:fd1f07a4a0ff 75 printf("Light intensity: %i%%\n", helper_get_sensor_read_in_percent(light_sensor_reading));
tuxx0046 9:fd1f07a4a0ff 76 printf("Rotary turned: %i%%\n", helper_get_sensor_read_in_percent(rotary_reading));
tuxx0046 6:aecab8e3acad 77 led_set_blink_rate(light_sensor_reading);
tuxx0046 6:aecab8e3acad 78 wait_us(1000000);
tuxx0046 9:fd1f07a4a0ff 79 */
tuxx0046 4:1a12157689a7 80
tuxx0046 9:fd1f07a4a0ff 81 /** 1/13/2021 Used to test the controller and make sure that it functions.*/
tuxx0046 2:90d31841523a 82 /**
tuxx0046 2:90d31841523a 83 printf("This is a test.\n");
tuxx0046 2:90d31841523a 84 myled = 1;
tuxx0046 2:90d31841523a 85 wait_us(1000000);
tuxx0046 2:90d31841523a 86 myled = 0;
tuxx0046 2:90d31841523a 87 wait_us(1000000);
tuxx0046 2:90d31841523a 88 */
tuxx0046 2:90d31841523a 89 }
tuxx0046 6:aecab8e3acad 90
tuxx0046 6:aecab8e3acad 91 /**
tuxx0046 6:aecab8e3acad 92 printf("Mbed OS version: %d,%d,%d\n\n",MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
tuxx0046 6:aecab8e3acad 93 */
tuxx0046 0:ed4063a0a4d5 94 }