@@ -71,11 +71,17 @@ byte customCharData[8]; //Records incoming custom character data
71
71
byte customCharSpot = 0 ; // Keeps track of where we are in custCharData array
72
72
byte customCharNumber = 0 ; // LCDs can store 8 custom chars, this keeps track
73
73
74
+ // New variables for Set RGB command
75
+ byte rgbData[8 ]; // Records incoming backlight rgb data
76
+ byte rgbSpot = 0 ; // Keeps track of where we are in rgbData array
77
+
74
78
bool modeCommand = false ; // Used to indicate if a command byte has been received
75
79
bool modeSetting = false ; // Used to indicate if a setting byte has been received
76
80
bool modeContrast = false ; // First setting mode, then contrast change mode, then the value to change to
77
81
bool modeTWI = false ; // First setting mode, then TWI change mode, then the value to change to
78
82
bool modeRecordCustomChar = false ; // First setting mode, then custom char mode, then record 8 bytes
83
+ // New command mode for Set RGB
84
+ bool modeSetRGB = false ; // First setting mode, then RGB mode, then get 3 bytes
79
85
80
86
// Struct for circular data buffer
81
87
// Data received over UART, SPI and I2C are all sent into a single buffer
@@ -146,8 +152,8 @@ void updateDisplay()
146
152
buffer.tail = (buffer.tail + 1 ) % BUFFER_SIZE; // and update the tail to the next oldest
147
153
148
154
// If the last byte received wasn't special
149
- if (modeCommand == false && modeSetting == false && modeContrast == false && modeTWI == false && modeRecordCustomChar == false )
150
- {
155
+ if (modeCommand == false && modeSetting == false && modeContrast == false && modeTWI == false
156
+ && modeRecordCustomChar == false && modeSetRGB == false ) {
151
157
// Check to see if the incoming byte is special
152
158
if (incoming == SPECIAL_SETTING) modeSetting = true ; // SPECIAL_SETTING is 127
153
159
else if (incoming == SPECIAL_COMMAND) modeCommand = true ; // SPECIAL_COMMAND is 254
@@ -275,6 +281,10 @@ void updateDisplay()
275
281
currentFrame[characterCount++] = incoming; // Record this character to the display buffer
276
282
if (characterCount == settingLCDwidth * settingLCDlines) characterCount = 0 ; // Wrap condition
277
283
}
284
+ // Set Backlight RGB in one command to eliminate flicker
285
+ else if (incoming == 43 ) {
286
+ modeSetRGB = true ;
287
+ }
278
288
modeSetting = false ;
279
289
}
280
290
else if (modeTWI == true )
@@ -421,6 +431,20 @@ void updateDisplay()
421
431
changeContrast (incoming);
422
432
modeContrast = false ; // Exit this mode
423
433
}
434
+ else if (modeSetRGB == true )
435
+ {
436
+ // We get into this mode if the user has sent the correct setting command
437
+ rgbData[rgbSpot] = incoming; // Record this byte to the array
438
+
439
+ rgbSpot++;
440
+ if (rgbSpot > 2 )
441
+ {
442
+ // Once we have 3 bytes, stop listening and change the backlight color
443
+ rgbSpot = 0 ;
444
+ changeBacklightRGB (rgbData[0 ], rgbData[1 ], rgbData[2 ]);
445
+ modeSetRGB = false ; // Exit this mode
446
+ } // if (rgbSpot > 2)
447
+ } // else if modeSetRGB
424
448
425
449
}
426
450
0 commit comments