Please be aware of all shipping deadlines before placing your order - we cannot guarantee orders will arrive before Christmas!

usb plus serial backpack
Moderators: adafruit_support_bill, adafruit

usb plus serial backpack

by Harvtech on Sun Sep 29, 2013 8:47 pm

I have assembled the backpack and mounted it on the back of the supplied 16x2 LCD with RGB backlight.
It works as expected with the code supplied in the tutorial obtained at http://learn.adafruit.com/usb-plus-serial-backpack.
However I do not understand the portion of the code that changes the backlight color included below.

Code: Select all | TOGGLE FULL SIZE
void loop() {
// adjust colors
for (red = 0; red < 255; red++) {
lcd.write(0xFE);
lcd.write(0xD0);
lcd.write(red);
lcd.write((uint8_t)0);
lcd.write(255 - red);
delay(10); // give it some time to adjust the backlight!
}
for (green = 0; green < 255; green++) {
lcd.write(0xFE);
lcd.write(0xD0);
lcd.write(255-green);
lcd.write(green);
lcd.write((uint8_t)0);
delay(10); // give it some time to adjust the backlight!
}
for (blue = 0; blue < 255; blue++) {
lcd.write(0xFE);
lcd.write(0xD0);
lcd.write((uint8_t)0);
lcd.write(255-blue);
lcd.write(blue);
delay(10); // give it some time to adjust the backlight!
}
}


I understand that the commands:
lcd.write(0xFE);
lcd.write(0xD0);
are required to set RGB backlight color. However what follows to actually specify the color needs further explanation.
Last edited by adafruit_support_bill on Mon Sep 30, 2013 6:27 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code
Harvtech
 
Posts: 2
Joined: Sun Sep 29, 2013 8:22 pm

Re: usb plus serial backpack

by 1chicagodave on Sun Sep 29, 2013 9:35 pm

Does this help?

http://learn.adafruit.com/usb-plus-serial-backpack/command-reference
Set RGB Backlight Color - 0xFE 0xD0 - Sets the backlight to the red, green and blue component colors. The values of can range from 0 to 255 (one byte). This is saved to EEPROM

Code: Select all | TOGGLE FULL SIZE

lcd.write(0xFE);  // Tell backpack that a command is coming next
lcd.write(0xD0);  // Set backlight to the following values....
lcd.write(red);                    // RED VALUE (0-255)
lcd.write((uint8_t)0);            // GREEN VALUE (0-255)
lcd.write(255 - red);              // BLUE VALUE (0-255)
Please forgive my hyperanthropomorphization.
Every answer reveals new questions.
And, yes... there's always a better way to 'do that'.
User avatar
1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am
Location: Chicago

Re: usb plus serial backpack

by Harvtech on Mon Sep 30, 2013 5:07 pm

Now I understand that following the command is one byte for each color in RGB order ranging in value from 0 to 255. That makes sense but it was not exactly spelled out that way in the command reference and there was no explanation in the example code. Thanks much for your explanation.
Harvtech
 
Posts: 2
Joined: Sun Sep 29, 2013 8:22 pm