@@ -48,25 +48,26 @@ static void EncoderClass::TimerISR() {ClassPtr->TimerHandler();} //
48
48
** RGB LEDs of the device. It is also the only place where the actual PWM values for RGB are set. **
49
49
*******************************************************************************************************************/
50
50
void 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 // //
63
64
if (_RedTarget !=255 &&_RedActual==_RedTarget) _RedTarget++; // Fade Red if max has been reached //
64
65
if (_GreenTarget!=255 &&_GreenActual==_GreenTarget) _GreenTarget++; // Fade Green " " //
65
66
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 //
66
70
} // 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 //
70
71
} // of if-then we need to do something // //
71
72
} // of method FaderButtonHandler() // //
72
73
/* ******************************************************************************************************************
@@ -83,6 +84,11 @@ void EncoderClass::PushButtonHandler() { //
83
84
_RedTarget = _ColorPushButtonR; // Set target color //
84
85
_GreenTarget = _ColorPushButtonG; // Set target color //
85
86
_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 // //
86
92
} // of if-then we have a valid pushbutton event // //
87
93
} // of method PushButtonHandler() // //
88
94
/* ******************************************************************************************************************
@@ -110,6 +116,11 @@ void EncoderClass::PushButtonHandler() { //
110
116
_BlueTarget = _ColorCCWB; // Set target color //
111
117
} // of if-then a CCW turn // //
112
118
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 // //
113
124
} // of method RotateHandler() // //
114
125
/* ******************************************************************************************************************
115
126
** function ButtonPushes() returns number of button pushes since the last call and resets the value **
@@ -123,9 +134,18 @@ uint8_t EncoderClass::GetButton() { //
123
134
** function SetColor() is called to set the RGB values to set when the button is pushed **
124
135
*******************************************************************************************************************/
125
136
void 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 //
126
140
_RedTarget = R; // set internal values //
127
141
_GreenTarget = G; // set internal values //
128
142
_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 // //
129
149
} // of method SetColor // //
130
150
/* ******************************************************************************************************************
131
151
** function SetPushButtonColor() is called to set the RGB values to set when the button is pushed **
0 commit comments