Hello, I am working with a color controlled adafruit LCD screen and backpack with an Arduino Uno. tap the screen can be found here: RGB backlight negative LCD 16x2 + extras [RGB on black] : ID 399 : $13.95 : Adafruit Industries, Unique & fun DIY electronics and kits
and the backpack can be found here: i2c / SPI character LCD backpack - STEMMA QT / Qwiic : ID 292 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits
I have pins 1-16 on the backpack soldered to pins 1-16 on the LCD screen, and then 2 jumper wires soldered to pins 17 and 18 on the LCD screen. I then have ground and 5V connected from the backpack to the Arduino, DAT connected to A4, and CLK connected to A5. Finally, I have the green and blue jumper wires connected from pins 17 and 18 on the LCD screen to pins 5 and 6 on the Arduino.
I am writing a little test program to try to make the LCD backlight turn green, blue, and red, separately. I have found from example programs that I can control the red backlight with the functions setBacklight (from the liquid crystal library). I can only control it on or off, which is fine. From what I've read online, I should be able to control the blue and green backlights on a sliding scale from 0 to 255, using the analogWrite function on a PWM pin. However, this isn't working. Anytime I try to use this function to write anything to the blue or green pin, or even try to initialize these pins into output mode, they turn the corresponding backlight on all the way and I can't turn it off (even if I write a value of 0 to it). Anyone know what's going on? The analog control isn't really important to me--I just want to be able to make the screen red, green, or blue.
Here is my code:
#include "Wire.h"
#include "LiquidCrystal.h"
#include <avr/sleep.h>
LiquidCrystal lcd(0);
//LCD backlight pins
int backlightGreenPin = 5;
int backlightBluePin = 6;
void setup()
{
//if i uncomment either of these lines, the corresponding backlight turns on all the way and can't be turned off
//by any method I know of
//pinMode(backlightGreenPin, OUTPUT);
//pinMode(backlightBluePin, OUTPUT);
//initialize LED screen
lcd.begin(16, 2);
//green
/*
lcd.setBacklight(LOW); //turn off red backlight
analogWrite(backlightBluePin,0); //turn off blue light
analogWrite(backlightGreenPin,255); //turn up green light all the way
delay(1000);
*/
/*
//blue
lcd.setBacklight(LOW); //turn off red backlight
analogWrite(backlightGreenPin,0); //turn off green light
analogWrite(backlightBluePin,255); //turn up blue light all the way
delay(1000);
*/
//red
//any value between zero and 255 produces the same result, which is to turn on the corresponding backlight all the way
analogWrite(backlightBluePin,0); //turn off blue light
analogWrite(backlightGreenPin,0); //turn off green light
lcd.setBacklight(HIGH); //turn on red backlight //this works, and if I change it to low, it will turn off the red light
}
void loop()
{}