School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
led_functions.h@20:9d4450357ce7, 2021-01-21 (annotated)
- Committer:
- tuxx0046
- Date:
- Thu Jan 21 12:43:03 2021 +0000
- Revision:
- 20:9d4450357ce7
- Parent:
- 14:3ac7c08dbc52
Updated libraries used section in comments in main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuxx0046 | 6:aecab8e3acad | 1 | /** |
tuxx0046 | 10:137cf2c92871 | 2 | @file led_functions.h |
tuxx0046 | 10:137cf2c92871 | 3 | @author Tu Tri Huynh |
tuxx0046 | 10:137cf2c92871 | 4 | @date January 14, 2021 |
tuxx0046 | 10:137cf2c92871 | 5 | @brief Functions to control Grove LED. |
tuxx0046 | 6:aecab8e3acad | 6 | */ |
tuxx0046 | 6:aecab8e3acad | 7 | |
tuxx0046 | 6:aecab8e3acad | 8 | /** |
tuxx0046 | 6:aecab8e3acad | 9 | This function will use the sensor_value and determine LED blinking rate. |
tuxx0046 | 9:fd1f07a4a0ff | 10 | The closer the value is to 0.00f the more frequent it will blink or even completely light up. |
tuxx0046 | 10:137cf2c92871 | 11 | @value Float value from the read() function in analog units. Must be between 0 and 1. |
tuxx0046 | 6:aecab8e3acad | 12 | 1/14/2021 |
tuxx0046 | 6:aecab8e3acad | 13 | */ |
tuxx0046 | 6:aecab8e3acad | 14 | void led_set_blink_rate(float value) |
tuxx0046 | 6:aecab8e3acad | 15 | { |
tuxx0046 | 6:aecab8e3acad | 16 | /// Turn on LED completely (no blinking) |
tuxx0046 | 6:aecab8e3acad | 17 | if (value < 0.10f) { |
tuxx0046 | 6:aecab8e3acad | 18 | led.period(1.00f); |
tuxx0046 | 6:aecab8e3acad | 19 | led.write(1.00f); |
tuxx0046 | 6:aecab8e3acad | 20 | } |
tuxx0046 | 14:3ac7c08dbc52 | 21 | /// Blink very fast |
tuxx0046 | 6:aecab8e3acad | 22 | else if (value >= 0.10f && value < 0.30f) { |
tuxx0046 | 14:3ac7c08dbc52 | 23 | led.period(0.13f); |
tuxx0046 | 14:3ac7c08dbc52 | 24 | led.write(0.25f); |
tuxx0046 | 14:3ac7c08dbc52 | 25 | } |
tuxx0046 | 14:3ac7c08dbc52 | 26 | /// Blink fast |
tuxx0046 | 14:3ac7c08dbc52 | 27 | else if (value >= 0.30f && value < 0.50f) { |
tuxx0046 | 6:aecab8e3acad | 28 | led.period(0.25f); |
tuxx0046 | 6:aecab8e3acad | 29 | led.write(0.50f); |
tuxx0046 | 6:aecab8e3acad | 30 | } |
tuxx0046 | 14:3ac7c08dbc52 | 31 | /// Blink |
tuxx0046 | 14:3ac7c08dbc52 | 32 | else if (value >= 0.50f && value < 0.70f) { |
tuxx0046 | 6:aecab8e3acad | 33 | led.period(0.50f); |
tuxx0046 | 6:aecab8e3acad | 34 | led.write(0.50f); |
tuxx0046 | 6:aecab8e3acad | 35 | } |
tuxx0046 | 14:3ac7c08dbc52 | 36 | /// Blink slow |
tuxx0046 | 14:3ac7c08dbc52 | 37 | else if (value >= 0.70f && value < 0.90f) { |
tuxx0046 | 6:aecab8e3acad | 38 | led.period(1.00f); |
tuxx0046 | 6:aecab8e3acad | 39 | led.write(0.50f); |
tuxx0046 | 6:aecab8e3acad | 40 | } |
tuxx0046 | 6:aecab8e3acad | 41 | /// If value is 1.00 turn off LED |
tuxx0046 | 6:aecab8e3acad | 42 | else { |
tuxx0046 | 6:aecab8e3acad | 43 | led.period(1.00f); |
tuxx0046 | 6:aecab8e3acad | 44 | led.write(0.00f); |
tuxx0046 | 6:aecab8e3acad | 45 | } |
tuxx0046 | 6:aecab8e3acad | 46 | //printf("Blink rate on this value: %0.2f\n", value); |
tuxx0046 | 6:aecab8e3acad | 47 | } |