Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Servo ros_lib_kinetic
LED.cpp
00001 /*-------------------------------------------------------------------------------- 00002 Filename: LED.cpp 00003 Description: Holds source code for configuring the RGB LED and also buzzer becuase 00004 where else do I put it :P 00005 --------------------------------------------------------------------------------*/ 00006 00007 #include "LED.h" 00008 00009 /*-------------------------------------------------------------------------------- 00010 Function name: cRGB_LED 00011 Input Parameters: N/A 00012 Output Parameters: N/A 00013 Description: Class constructor (Initialisation upon creating class) 00014 ----------------------------------------------------------------------------------*/ 00015 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) 00016 { 00017 // Set initial condition of PWM 00018 _DIAG_BLU.period(0.001); //1KHz 00019 _DIAG_BLU = 0; 00020 00021 // Set initial condition of PWM 00022 _DIAG_GRN.period(0.001); //1KHz 00023 _DIAG_GRN = 0; 00024 00025 // Initial condition of output enables 00026 _DIAG_RED = 0; 00027 00028 //Initialise battery level 00029 _battery_level = 0; 00030 00031 } 00032 00033 /*-------------------------------------------------------------------------------- 00034 Function name: cRGB_LED 00035 Input Parameters: N/A 00036 Output Parameters: N/A 00037 Description: Turns on red led 00038 ----------------------------------------------------------------------------------*/ 00039 void cRGB_LED::red_led() 00040 { 00041 _DIAG_RED = 1; //Enable red 00042 _DIAG_BLU = 0.0; //Disable Blue 00043 _DIAG_GRN = 0.0; //Disable Green 00044 } 00045 00046 /*-------------------------------------------------------------------------------- 00047 Function name: blue_led() 00048 Input Parameters: N/A 00049 Output Parameters: N/A 00050 Description: Turns on blue led 00051 ----------------------------------------------------------------------------------*/ 00052 void cRGB_LED::blue_led() 00053 { 00054 _DIAG_RED = 0; //Disable Red 00055 _DIAG_BLU = 1.0; //Enable Blue 00056 _DIAG_GRN = 0.0; //Enable Green 00057 } 00058 00059 /*-------------------------------------------------------------------------------- 00060 Function name: green_led() 00061 Input Parameters: N/A 00062 Output Parameters: N/A 00063 Description: Turns on green led 00064 ----------------------------------------------------------------------------------*/ 00065 void cRGB_LED::green_led() 00066 { 00067 _DIAG_RED = 0; //Disable Red 00068 _DIAG_BLU = 0.0; //Disable Blue 00069 _DIAG_GRN = 1.0; //Enable Green 00070 } 00071 00072 /*-------------------------------------------------------------------------------- 00073 Function name: yellow_led() 00074 Input Parameters: N/A 00075 Output Parameters: N/A 00076 Description: Turns on yellow led 00077 ----------------------------------------------------------------------------------*/ 00078 void cRGB_LED::yellow_led() 00079 { 00080 _DIAG_RED = 1; //Enable Red 00081 _DIAG_BLU = 0.0; //Disable Blue 00082 _DIAG_GRN = 0.35; //Enable Green at 35% duty 00083 } 00084 00085 /*-------------------------------------------------------------------------------- 00086 Function name: ORANGE_LED () 00087 Input Parameters: N/A 00088 Output Parameters: N/A 00089 Description: Turns on orange led 00090 ----------------------------------------------------------------------------------*/ 00091 void cRGB_LED::orange_led() 00092 { 00093 _DIAG_RED = 1.0f; //Enable Red 00094 _DIAG_BLU = 0.0f; //Disable Blue 00095 _DIAG_GRN = 0.647f; //Enable Green at 35% duty 00096 } 00097 00098 /*-------------------------------------------------------------------------------- 00099 Function name: led_off() 00100 Input Parameters: N/A 00101 Output Parameters: N/A 00102 Description: Turns the led off 00103 ----------------------------------------------------------------------------------*/ 00104 void cRGB_LED::led_off() 00105 { 00106 _DIAG_RED = 0; //Disable Red 00107 _DIAG_BLU = 0; //Disable Blue 00108 _DIAG_GRN = 0; //Disable Green 00109 } 00110 00111 00112 /*-------------------------------------------------------------------------------- 00113 Function name: record_power() 00114 Input Parameters: vBatt - the battery voltage level 00115 Output Parameters: N/A 00116 Description: Stores an input battery level privately in the LED class 00117 ----------------------------------------------------------------------------------*/ 00118 void cRGB_LED::record_power(float vBatt) 00119 { 00120 _battery_level = vBatt; //Record battery level for LED class 00121 } 00122 00123 /*-------------------------------------------------------------------------------- 00124 Function name: display_power() 00125 Input Parameters: N/A 00126 Output Parameters: N/A 00127 Description: Sets the LED colour based on the input voltage levels 00128 ----------------------------------------------------------------------------------*/ 00129 void cRGB_LED::display_power() 00130 { 00131 if (_battery_level >= 4.0f) 00132 { 00133 green_led(); //Power above 70% 00134 } 00135 else if (_battery_level < 4.0f){ 00136 00137 orange_led(); //Power above 40% 00138 } 00139 else if (_battery_level < 3.70f) 00140 { 00141 red_led(); //Low power needs charging 00142 } 00143 else{ 00144 00145 //SOMETHING WENT WRONG! 00146 } 00147 }
Generated on Wed Jul 13 2022 08:03:54 by
1.7.2