with the tof code
Dependencies: mbed Servo ros_lib_kinetic
RGB_LED/LED.cpp@9:326b8f261ef0, 2020-01-04 (annotated)
- Committer:
- Alexshawcroft
- Date:
- Sat Jan 04 21:35:25 2020 +0000
- Revision:
- 9:326b8f261ef0
- Parent:
- 7:8248af58df5a
oh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Stumi | 6:2cc2aac35868 | 1 | /*-------------------------------------------------------------------------------- |
Stumi | 6:2cc2aac35868 | 2 | Filename: LED.cpp |
Stumi | 6:2cc2aac35868 | 3 | Description: Holds source code for configuring the RGB LED and also buzzer becuase |
Stumi | 6:2cc2aac35868 | 4 | where else do I put it :P |
Stumi | 6:2cc2aac35868 | 5 | --------------------------------------------------------------------------------*/ |
Stumi | 6:2cc2aac35868 | 6 | |
Stumi | 5:bc5081f0c063 | 7 | #include "LED.h" |
Stumi | 5:bc5081f0c063 | 8 | |
Stumi | 6:2cc2aac35868 | 9 | /*-------------------------------------------------------------------------------- |
Stumi | 6:2cc2aac35868 | 10 | Function name: cRGB_LED |
Stumi | 6:2cc2aac35868 | 11 | Input Parameters: N/A |
Stumi | 6:2cc2aac35868 | 12 | Output Parameters: N/A |
Stumi | 6:2cc2aac35868 | 13 | Description: Class constructor (Initialisation upon creating class) |
Stumi | 6:2cc2aac35868 | 14 | ----------------------------------------------------------------------------------*/ |
Stumi | 6:2cc2aac35868 | 15 | cRGB_LED::cRGB_LED(DigitalOut DIAG_RED, PwmOut DIAG_BLU, PwmOut DIAG_GRN): _DIAG_RED(DIAG_RED), _DIAG_BLU(DIAG_BLU), _DIAG_GRN(DIAG_GRN) |
Stumi | 5:bc5081f0c063 | 16 | { |
Stumi | 5:bc5081f0c063 | 17 | // Set initial condition of PWM |
Stumi | 5:bc5081f0c063 | 18 | _DIAG_BLU.period(0.001); //1KHz |
Stumi | 5:bc5081f0c063 | 19 | _DIAG_BLU = 0; |
Stumi | 5:bc5081f0c063 | 20 | |
Stumi | 5:bc5081f0c063 | 21 | // Set initial condition of PWM |
Stumi | 5:bc5081f0c063 | 22 | _DIAG_GRN.period(0.001); //1KHz |
Stumi | 5:bc5081f0c063 | 23 | _DIAG_GRN = 0; |
Stumi | 5:bc5081f0c063 | 24 | |
Stumi | 5:bc5081f0c063 | 25 | // Initial condition of output enables |
Stumi | 5:bc5081f0c063 | 26 | _DIAG_RED = 0; |
Stumi | 7:8248af58df5a | 27 | |
Stumi | 7:8248af58df5a | 28 | //Initialise battery level |
Stumi | 7:8248af58df5a | 29 | _battery_level = 0; |
Stumi | 7:8248af58df5a | 30 | |
Stumi | 5:bc5081f0c063 | 31 | } |
Stumi | 5:bc5081f0c063 | 32 | |
Stumi | 6:2cc2aac35868 | 33 | /*-------------------------------------------------------------------------------- |
Stumi | 6:2cc2aac35868 | 34 | Function name: cRGB_LED |
Stumi | 6:2cc2aac35868 | 35 | Input Parameters: N/A |
Stumi | 6:2cc2aac35868 | 36 | Output Parameters: N/A |
Stumi | 6:2cc2aac35868 | 37 | Description: Turns on red led |
Stumi | 6:2cc2aac35868 | 38 | ----------------------------------------------------------------------------------*/ |
Stumi | 6:2cc2aac35868 | 39 | void cRGB_LED::red_led() |
Stumi | 5:bc5081f0c063 | 40 | { |
Stumi | 6:2cc2aac35868 | 41 | _DIAG_RED = 1; //Enable red |
Stumi | 6:2cc2aac35868 | 42 | _DIAG_BLU = 0.0; //Disable Blue |
Stumi | 6:2cc2aac35868 | 43 | _DIAG_GRN = 0.0; //Disable Green |
Stumi | 5:bc5081f0c063 | 44 | } |
Stumi | 5:bc5081f0c063 | 45 | |
Stumi | 6:2cc2aac35868 | 46 | /*-------------------------------------------------------------------------------- |
Stumi | 6:2cc2aac35868 | 47 | Function name: blue_led() |
Stumi | 6:2cc2aac35868 | 48 | Input Parameters: N/A |
Stumi | 6:2cc2aac35868 | 49 | Output Parameters: N/A |
Stumi | 6:2cc2aac35868 | 50 | Description: Turns on blue led |
Stumi | 6:2cc2aac35868 | 51 | ----------------------------------------------------------------------------------*/ |
Stumi | 6:2cc2aac35868 | 52 | void cRGB_LED::blue_led() |
Stumi | 5:bc5081f0c063 | 53 | { |
Stumi | 6:2cc2aac35868 | 54 | _DIAG_RED = 0; //Disable Red |
Stumi | 6:2cc2aac35868 | 55 | _DIAG_BLU = 1.0; //Enable Blue |
Stumi | 6:2cc2aac35868 | 56 | _DIAG_GRN = 0.0; //Enable Green |
Stumi | 5:bc5081f0c063 | 57 | } |
Stumi | 5:bc5081f0c063 | 58 | |
Stumi | 6:2cc2aac35868 | 59 | /*-------------------------------------------------------------------------------- |
Stumi | 6:2cc2aac35868 | 60 | Function name: green_led() |
Stumi | 6:2cc2aac35868 | 61 | Input Parameters: N/A |
Stumi | 6:2cc2aac35868 | 62 | Output Parameters: N/A |
Stumi | 6:2cc2aac35868 | 63 | Description: Turns on green led |
Stumi | 6:2cc2aac35868 | 64 | ----------------------------------------------------------------------------------*/ |
Stumi | 6:2cc2aac35868 | 65 | void cRGB_LED::green_led() |
Stumi | 5:bc5081f0c063 | 66 | { |
Stumi | 6:2cc2aac35868 | 67 | _DIAG_RED = 0; //Disable Red |
Stumi | 6:2cc2aac35868 | 68 | _DIAG_BLU = 0.0; //Disable Blue |
Stumi | 6:2cc2aac35868 | 69 | _DIAG_GRN = 1.0; //Enable Green |
Stumi | 5:bc5081f0c063 | 70 | } |
Stumi | 5:bc5081f0c063 | 71 | |
Stumi | 6:2cc2aac35868 | 72 | /*-------------------------------------------------------------------------------- |
Stumi | 6:2cc2aac35868 | 73 | Function name: yellow_led() |
Stumi | 6:2cc2aac35868 | 74 | Input Parameters: N/A |
Stumi | 6:2cc2aac35868 | 75 | Output Parameters: N/A |
Stumi | 6:2cc2aac35868 | 76 | Description: Turns on yellow led |
Stumi | 6:2cc2aac35868 | 77 | ----------------------------------------------------------------------------------*/ |
Stumi | 6:2cc2aac35868 | 78 | void cRGB_LED::yellow_led() |
Stumi | 5:bc5081f0c063 | 79 | { |
Stumi | 6:2cc2aac35868 | 80 | _DIAG_RED = 1; //Enable Red |
Stumi | 6:2cc2aac35868 | 81 | _DIAG_BLU = 0.0; //Disable Blue |
Stumi | 6:2cc2aac35868 | 82 | _DIAG_GRN = 0.35; //Enable Green at 35% duty |
Stumi | 5:bc5081f0c063 | 83 | } |
Stumi | 5:bc5081f0c063 | 84 | |
Stumi | 6:2cc2aac35868 | 85 | /*-------------------------------------------------------------------------------- |
Stumi | 7:8248af58df5a | 86 | Function name: ORANGE_LED () |
Stumi | 7:8248af58df5a | 87 | Input Parameters: N/A |
Stumi | 7:8248af58df5a | 88 | Output Parameters: N/A |
Stumi | 7:8248af58df5a | 89 | Description: Turns on orange led |
Stumi | 7:8248af58df5a | 90 | ----------------------------------------------------------------------------------*/ |
Stumi | 7:8248af58df5a | 91 | void cRGB_LED::orange_led() |
Stumi | 7:8248af58df5a | 92 | { |
Stumi | 7:8248af58df5a | 93 | _DIAG_RED = 1.0f; //Enable Red |
Stumi | 7:8248af58df5a | 94 | _DIAG_BLU = 0.0f; //Disable Blue |
Stumi | 7:8248af58df5a | 95 | _DIAG_GRN = 0.647f; //Enable Green at 35% duty |
Stumi | 7:8248af58df5a | 96 | } |
Stumi | 7:8248af58df5a | 97 | |
Stumi | 7:8248af58df5a | 98 | /*-------------------------------------------------------------------------------- |
Stumi | 6:2cc2aac35868 | 99 | Function name: led_off() |
Stumi | 6:2cc2aac35868 | 100 | Input Parameters: N/A |
Stumi | 6:2cc2aac35868 | 101 | Output Parameters: N/A |
Stumi | 6:2cc2aac35868 | 102 | Description: Turns the led off |
Stumi | 6:2cc2aac35868 | 103 | ----------------------------------------------------------------------------------*/ |
Stumi | 6:2cc2aac35868 | 104 | void cRGB_LED::led_off() |
Stumi | 5:bc5081f0c063 | 105 | { |
Stumi | 6:2cc2aac35868 | 106 | _DIAG_RED = 0; //Disable Red |
Stumi | 6:2cc2aac35868 | 107 | _DIAG_BLU = 0; //Disable Blue |
Stumi | 6:2cc2aac35868 | 108 | _DIAG_GRN = 0; //Disable Green |
Stumi | 7:8248af58df5a | 109 | } |
Stumi | 7:8248af58df5a | 110 | |
Stumi | 7:8248af58df5a | 111 | |
Stumi | 7:8248af58df5a | 112 | /*-------------------------------------------------------------------------------- |
Stumi | 7:8248af58df5a | 113 | Function name: record_power() |
Stumi | 7:8248af58df5a | 114 | Input Parameters: vBatt - the battery voltage level |
Stumi | 7:8248af58df5a | 115 | Output Parameters: N/A |
Stumi | 7:8248af58df5a | 116 | Description: Stores an input battery level privately in the LED class |
Stumi | 7:8248af58df5a | 117 | ----------------------------------------------------------------------------------*/ |
Stumi | 7:8248af58df5a | 118 | void cRGB_LED::record_power(float vBatt) |
Stumi | 7:8248af58df5a | 119 | { |
Stumi | 7:8248af58df5a | 120 | _battery_level = vBatt; //Record battery level for LED class |
Stumi | 7:8248af58df5a | 121 | } |
Stumi | 7:8248af58df5a | 122 | |
Stumi | 7:8248af58df5a | 123 | /*-------------------------------------------------------------------------------- |
Stumi | 7:8248af58df5a | 124 | Function name: display_power() |
Stumi | 7:8248af58df5a | 125 | Input Parameters: N/A |
Stumi | 7:8248af58df5a | 126 | Output Parameters: N/A |
Stumi | 7:8248af58df5a | 127 | Description: Sets the LED colour based on the input voltage levels |
Stumi | 7:8248af58df5a | 128 | ----------------------------------------------------------------------------------*/ |
Stumi | 7:8248af58df5a | 129 | void cRGB_LED::display_power() |
Stumi | 7:8248af58df5a | 130 | { |
Stumi | 7:8248af58df5a | 131 | if (_battery_level >= 4.0f) |
Stumi | 7:8248af58df5a | 132 | { |
Stumi | 7:8248af58df5a | 133 | green_led(); //Power above 70% |
Stumi | 7:8248af58df5a | 134 | } |
Stumi | 7:8248af58df5a | 135 | else if (_battery_level < 4.0f){ |
Stumi | 7:8248af58df5a | 136 | |
Stumi | 7:8248af58df5a | 137 | orange_led(); //Power above 40% |
Stumi | 7:8248af58df5a | 138 | } |
Stumi | 7:8248af58df5a | 139 | else if (_battery_level < 3.70f) |
Stumi | 7:8248af58df5a | 140 | { |
Stumi | 7:8248af58df5a | 141 | red_led(); //Low power needs charging |
Stumi | 7:8248af58df5a | 142 | } |
Stumi | 7:8248af58df5a | 143 | else{ |
Stumi | 7:8248af58df5a | 144 | |
Stumi | 7:8248af58df5a | 145 | //SOMETHING WENT WRONG! |
Stumi | 7:8248af58df5a | 146 | } |
Stumi | 7:8248af58df5a | 147 | } |