This demo shows how to to change the Backlight level of the CYD display. The function accepts a percentage value (0 – 100), where 0 is off and 100 is full brightness.

The function is

/*
* @Summary Sets the Backlight between 0 and 100
* @param Percentage Value (0-100)
* @return none
*/
void set_CYDBackLight(uint8_t percent){
  // Cap the the percentage value to 100
  if (percent > 100 ) {percent = 100; }   
  // Change the percentage value to 0 - 255 (Rounded to the nearest Integer)
  percent = int((percent * 2.55) + .5);
  // Write the value to the Backlight GPIO pin
  analogWrite(BL_GPIO, percent);
}

You also need add the following to your code

At the start add: #define BL_GPIO 21 // Define Backlight GPOI pin

In the Setup function add: pinMode(BL_GPIO, INPUT); // Set Backlight GPIO pin as an Input

This will initially set the Backlight to 0 (Display off), you will need to add: set_CYDBackLight(100); // Set Backlight 100%

Demo code can be downloaded here

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *