![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Copy_Assignment3
Dependencies: mbed MCP23017 WattBob_TextLCD mbed-rtos
include/my_tools.h@1:d980a57e422a, 2018-03-28 (annotated)
- Committer:
- aoc2
- Date:
- Wed Mar 28 18:53:05 2018 +0000
- Revision:
- 1:d980a57e422a
- Parent:
- 0:8940db3353d7
Publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aoc2 | 0:8940db3353d7 | 1 | #include <vector> |
aoc2 | 0:8940db3353d7 | 2 | #include "mbed.h" |
aoc2 | 0:8940db3353d7 | 3 | #include "my_structures.h" |
aoc2 | 0:8940db3353d7 | 4 | #include "MCP23017.h" |
aoc2 | 0:8940db3353d7 | 5 | #include "WattBob_TextLCD.h" |
aoc2 | 0:8940db3353d7 | 6 | |
aoc2 | 0:8940db3353d7 | 7 | #pragma once |
aoc2 | 0:8940db3353d7 | 8 | #ifndef __MY_TOOLS_H__ |
aoc2 | 0:8940db3353d7 | 9 | #define __MY_TOOLS_H__ |
aoc2 | 0:8940db3353d7 | 10 | |
aoc2 | 0:8940db3353d7 | 11 | /******************************************************************************* |
aoc2 | 0:8940db3353d7 | 12 | * FUNCTION TOOLS DECLARATION |
aoc2 | 0:8940db3353d7 | 13 | * To Simplify the code of the task themselves |
aoc2 | 0:8940db3353d7 | 14 | ******************************************************************************/ |
aoc2 | 0:8940db3353d7 | 15 | |
aoc2 | 0:8940db3353d7 | 16 | /** Read an analog input and return a float between 0 and 1 |
aoc2 | 0:8940db3353d7 | 17 | * |
aoc2 | 0:8940db3353d7 | 18 | * @param: pin [AnalogIn] |
aoc2 | 0:8940db3353d7 | 19 | * Pin to read |
aoc2 | 0:8940db3353d7 | 20 | * |
aoc2 | 0:8940db3353d7 | 21 | * @return: float between 0 and 1 |
aoc2 | 0:8940db3353d7 | 22 | */ |
aoc2 | 0:8940db3353d7 | 23 | float readAnalogInput(AnalogIn pin); |
aoc2 | 0:8940db3353d7 | 24 | |
aoc2 | 0:8940db3353d7 | 25 | |
aoc2 | 0:8940db3353d7 | 26 | /** Delete the first value of the given vector |
aoc2 | 0:8940db3353d7 | 27 | * |
aoc2 | 0:8940db3353d7 | 28 | * @param: &vec - Vector whose first value is deleted |
aoc2 | 0:8940db3353d7 | 29 | */ |
aoc2 | 0:8940db3353d7 | 30 | void deleteFirstValueVec(vector<float> &vec); |
aoc2 | 0:8940db3353d7 | 31 | |
aoc2 | 0:8940db3353d7 | 32 | |
aoc2 | 0:8940db3353d7 | 33 | /** Switch on a DigitalOut led if the given float value is above some threshold |
aoc2 | 0:8940db3353d7 | 34 | * |
aoc2 | 0:8940db3353d7 | 35 | * @param: value [float] |
aoc2 | 0:8940db3353d7 | 36 | * Checked Value |
aoc2 | 0:8940db3353d7 | 37 | * @prama: led [DigitalOut] |
aoc2 | 0:8940db3353d7 | 38 | * Output pin used to show if the value goes above the threshold |
aoc2 | 0:8940db3353d7 | 39 | * @param: threshold [float] |
aoc2 | 0:8940db3353d7 | 40 | * Threshold value use to switch on or or the DigitalOut pin |
aoc2 | 0:8940db3353d7 | 41 | * |
aoc2 | 0:8940db3353d7 | 42 | * @return: int - 0 or 1, state of the DigitalOut pin |
aoc2 | 0:8940db3353d7 | 43 | */ |
aoc2 | 0:8940db3353d7 | 44 | int monitorValue(float value, DigitalOut led, float thresholdValue); |
aoc2 | 0:8940db3353d7 | 45 | |
aoc2 | 0:8940db3353d7 | 46 | |
aoc2 | 0:8940db3353d7 | 47 | /** Write on the LCD the odometer and speed values |
aoc2 | 0:8940db3353d7 | 48 | * |
aoc2 | 0:8940db3353d7 | 49 | * @param: &lcd [WattBob_TextLCD] |
aoc2 | 0:8940db3353d7 | 50 | * Reference to the screen to use to display information |
aoc2 | 0:8940db3353d7 | 51 | * @param: odometer [float] |
aoc2 | 0:8940db3353d7 | 52 | * Travelled distance in m, displayed in km |
aoc2 | 0:8940db3353d7 | 53 | * @param: avg [float] |
aoc2 | 0:8940db3353d7 | 54 | * Last average speed computed in m/s. Displayed in km/h |
aoc2 | 0:8940db3353d7 | 55 | */ |
aoc2 | 0:8940db3353d7 | 56 | void writeOnLCD(WattBob_TextLCD &lcd, float odometer, float avg); |
aoc2 | 0:8940db3353d7 | 57 | |
aoc2 | 0:8940db3353d7 | 58 | |
aoc2 | 0:8940db3353d7 | 59 | /** Update the PWM frequency of the right and left DigitalOut leds of the car |
aoc2 | 0:8940db3353d7 | 60 | * based on the state of the given switch |
aoc2 | 0:8940db3353d7 | 61 | * |
aoc2 | 0:8940db3353d7 | 62 | * @param: *myCar [carStructure] |
aoc2 | 0:8940db3353d7 | 63 | * Main structure used in the program, used to access the right |
aoc2 | 0:8940db3353d7 | 64 | * and left switch. |
aoc2 | 0:8940db3353d7 | 65 | * @param: right [bool] |
aoc2 | 0:8940db3353d7 | 66 | * State of the right switch |
aoc2 | 0:8940db3353d7 | 67 | * @param: left [bool] |
aoc2 | 0:8940db3353d7 | 68 | * State of the left switch. |
aoc2 | 0:8940db3353d7 | 69 | */ |
aoc2 | 0:8940db3353d7 | 70 | void updateLEDs(carStructure *myCar, bool right, bool left); |
aoc2 | 0:8940db3353d7 | 71 | |
aoc2 | 0:8940db3353d7 | 72 | #endif /*! __MY__TOOLS_H__ */ |