@@ -48,25 +48,26 @@ static void EncoderClass::TimerISR() {ClassPtr->TimerHandler();} //
4848** RGB LEDs of the device. It is also the only place where the actual PWM values for RGB are set. **
4949*******************************************************************************************************************/
5050void EncoderClass::TimerHandler () { // //
51- if (_LEDChanged || !(_RedActual==255 &&_GreenActual==255 &&_BlueActual==255 )){// Only check if LEDs aren't off //
52- _LEDChanged = false ; // Reset the value //
53- if (_RedActual!=_RedTarget) { // adjust accordingly //
54- if (_RedActual<_RedTarget) _RedActual++; else _RedActual--; // //
55- } // of if-then actual and target don't match // //
56- if (_GreenActual!=_GreenTarget) { // //
57- if (_GreenActual<_GreenTarget) _GreenActual++; else _GreenActual--; // //
58- } // of if-then actual and target don't match // //
59- if (_BlueActual!=_BlueTarget) { // //
60- if (_BlueTarget<_BlueTarget) _BlueActual++; else _BlueActual--; // //
61- } // of if-then actual and target don't match // //
62- if (_FadeMillis!=0 && millis ()%_FadeMillis==0 ) { // If we are fading colors, then //
51+ if (_LEDChanged || // Only check if LEDs aren't off //
52+ !(_RedActual==255 && _GreenActual==255 && _BlueActual==255 )) { // //
53+ if (millis ()%_FadeMillis==0 ) { // If we are fading colors, then //
54+ _LEDChanged = false ; // Reset the value //
55+ if (_RedActual!=_RedTarget) { // adjust accordingly //
56+ if (_RedActual<_RedTarget) _RedActual++; else _RedActual--; // //
57+ } // of if-then actual and target don't match // //
58+ if (_GreenActual!=_GreenTarget) { // //
59+ if (_GreenActual<_GreenTarget) _GreenActual++; else _GreenActual--; // //
60+ } // of if-then actual and target don't match // //
61+ if (_BlueActual!=_BlueTarget) { // //
62+ if (_BlueTarget<_BlueTarget) _BlueActual++; else _BlueActual--; // //
63+ } // of if-then actual and target don't match // //
6364 if (_RedTarget !=255 &&_RedActual==_RedTarget) _RedTarget++; // Fade Red if max has been reached //
6465 if (_GreenTarget!=255 &&_GreenActual==_GreenTarget) _GreenTarget++; // Fade Green " " //
6566 if (_BlueTarget !=255 &&_BlueActual==_BlueTarget) _BlueTarget++; // Fade Blue " " //
67+ analogWrite (_RedPin,_RedActual); // show the Red, //
68+ analogWrite (_GreenPin,_GreenActual); // Green, and //
69+ analogWrite (_BluePin,_BlueActual); // Blue values //
6670 } // of if-then we want to fade LED brightness // //
67- analogWrite (_RedPin,_RedActual); // show the Red, //
68- analogWrite (_GreenPin,_GreenActual); // Green, and //
69- analogWrite (_BluePin,_BlueActual); // Blue values //
7071 } // of if-then we need to do something // //
7172} // of method FaderButtonHandler() // //
7273/* ******************************************************************************************************************
@@ -83,6 +84,11 @@ void EncoderClass::PushButtonHandler() { //
8384 _RedTarget = _ColorPushButtonR; // Set target color //
8485 _GreenTarget = _ColorPushButtonG; // Set target color //
8586 _BlueTarget = _ColorPushButtonB; // Set target color //
87+ if (_FadeMillis==0 ) { // Manually set if no fade //
88+ analogWrite (_RedPin,_RedTarget); // show the Red, //
89+ analogWrite (_GreenPin,_GreenTarget); // Green, and //
90+ analogWrite (_BluePin,_BlueTarget); // Blue values //
91+ } // of if fading is turned off // //
8692 } // of if-then we have a valid pushbutton event // //
8793} // of method PushButtonHandler() // //
8894/* ******************************************************************************************************************
@@ -110,6 +116,11 @@ void EncoderClass::PushButtonHandler() { //
110116 _BlueTarget = _ColorCCWB; // Set target color //
111117 } // of if-then a CCW turn // //
112118 lastEncoded = encoded; // store the value for next time //
119+ if (_FadeMillis==0 ) { // Manually set if no fade //
120+ analogWrite (_RedPin,_RedTarget); // show the Red, //
121+ analogWrite (_GreenPin,_GreenTarget); // Green, and //
122+ analogWrite (_BluePin,_BlueTarget); // Blue values //
123+ } // of if fading is turned off // //
113124 } // of method RotateHandler() // //
114125/* ******************************************************************************************************************
115126** function ButtonPushes() returns number of button pushes since the last call and resets the value **
@@ -123,9 +134,18 @@ uint8_t EncoderClass::GetButton() { //
123134** function SetColor() is called to set the RGB values to set when the button is pushed **
124135*******************************************************************************************************************/
125136void EncoderClass::SetColor (const uint8_t R,const uint8_t G,const uint8_t B) {// //
137+ _RedActual = R; // set internal values //
138+ _GreenActual = G; // set internal values //
139+ _BlueActual = B; // set internal values //
126140 _RedTarget = R; // set internal values //
127141 _GreenTarget = G; // set internal values //
128142 _BlueTarget = B; // set internal values //
143+ _LEDChanged = true ; // Mark that we have a change //
144+ if (_FadeMillis==0 ) { // Manually set if no fade //
145+ analogWrite (_RedPin,_RedTarget); // show the Red, //
146+ analogWrite (_GreenPin,_GreenTarget); // Green, and //
147+ analogWrite (_BluePin,_BlueTarget); // Blue values //
148+ } // of if fading is turned off // //
129149} // of method SetColor // //
130150/* ******************************************************************************************************************
131151** function SetPushButtonColor() is called to set the RGB values to set when the button is pushed **
0 commit comments