Library for multi-pin RGB leds that encapsulates three PwmOut objects.
Diff: MultipinRGB.h
- Revision:
- 2:ecd3840bb6a7
- Parent:
- 1:ce9726c385f1
- Child:
- 3:327cc9243faf
diff -r ce9726c385f1 -r ecd3840bb6a7 MultipinRGB.h --- a/MultipinRGB.h Tue Mar 28 20:26:46 2017 +0000 +++ b/MultipinRGB.h Tue Mar 28 22:33:51 2017 +0000 @@ -50,7 +50,7 @@ * * while(1) * { -* leds.writeRGB(redDutyCycle, grnDutyCycle, bluDutyCycle); +* leds.writeLeds(redDutyCycle, grnDutyCycle, bluDutyCycle); * * printf("RGB Duty Cycles = %3.1f, %3.1f, %3.1f\r\n", * redDutyCycle, grnDutyCycle, bluDutyCycle); @@ -71,6 +71,13 @@ { public: + enum Led_e + { + Red, + Green, + Blue + }; + enum LedLogic_e { ActiveLow, @@ -97,29 +104,7 @@ ///@param[out] none /// ///@returns none - void writeRed(const float r); - - ///@brief Sets duty cycle for green led.\n - /// - ///On Entry: - ///@param[in] g - Duty cycle for led, 0.0 to 1.0 - /// - ///On Exit: - ///@param[out] none - /// - ///@returns none - void writeGreen(const float g); - - ///@brief Sets duty cycle for blue led.\n - /// - ///On Entry: - ///@param[in] b - Duty cycle for led, 0.0 to 1.0 - /// - ///On Exit: - ///@param[out] none - /// - ///@returns none - void writeBlue(const float b); + void writeLed(const Led_e led, const float dc); ///@brief Sets duty cycle for all three leds.\n /// @@ -132,18 +117,7 @@ ///@param[out] none /// ///@returns none - void writeRGB(const float r, const float g, const float b); - - ///@brief Sets pwm period for all three leds.\n - /// - ///On Entry: - ///@param[in] p - PWM period in seconds - /// - ///On Exit: - ///@param[out] none - /// - ///@returns none - void setPeriod(const float p); + void writeLeds(const float r, const float g, const float b); ///@brief Reads duty cycle for red led.\n /// @@ -154,29 +128,7 @@ ///@param[out] none /// ///@returns Current duty cycle for led, 0.0 to 1.0 - float readRed(); - - ///@brief Reads duty cycle for green led.\n - /// - ///On Entry: - ///@param[in] none - /// - ///On Exit: - ///@param[out] none - /// - ///@returns Current duty cycle for led, 0.0 to 1.0 - float readGreen(); - - ///@brief Reads duty cycle for blue led.\n - /// - ///On Entry: - ///@param[in] none - /// - ///On Exit: - ///@param[out] none - /// - ///@returns Current duty cycle for led, 0.0 to 1.0 - float readBlue(); + float readLed(const Led_e led); ///@brief Reads duty cycle for all three leds.\n /// @@ -191,7 +143,18 @@ ///@param[out] b - Current duty cycle for led, 0.0 to 1.0 /// ///@returns none - void readRGB(float& r, float& g, float& b); + void readLeds(float& r, float& g, float& b); + + ///@brief Sets pwm period for all three leds.\n + /// + ///On Entry: + ///@param[in] p - PWM period in seconds + /// + ///On Exit: + ///@param[out] none + /// + ///@returns none + void setPeriod(const float p); private: @@ -199,6 +162,8 @@ PwmOut m_green; PwmOut m_blue; + float m_redDc, m_grnDc, m_bluDc; + LedLogic_e m_ledActiveState; };