how to get Max back light brightness ILI9341 2.8" Adafruit

/*backlight test PWM = 12
  Due board
  Screen https://www.adafruit.com/product/1770
*/
#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>
MCUFRIEND_kbv tft;

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
//#define LCD_RESET A4

//Touchscreen X+ X- Y+ Y- pins
#define YP A5
#define XM A4
#define YM 10
#define XP 11
//tested as correct for new ADAFRUIT screen
#define TS_MINX 150
#define TS_MINY 90
#define TS_MAXX 900
#define TS_MAXY 800

#define BLACK       0x0000
#define BLUE        0x001F
#define CYAN        0x07FF
#define DARKCYAN    0x03EF
#define GREY1       0x8410
#define GREY2       0x4208
#define LIGHTGREY   0xC618
#define DARKGREY    0x7BEF
#define GREEN       0x07E0
#define DARKGREEN   0x03E0
#define GREENYELLOW 0xB7E0
#define MAGENTA     0xF81F
#define MAROON      0x7800
#define NAVY        0x000F
#define OLIVE       0x7BE0
#define ORANGE      0xFDA0
#define PINK        0xFC9F
#define PURPLE      0x780F
#define RED         0xF800
#define BRIGHT_RED  0xf810
#define WHITE       0xFFFF
#define YELLOW      0xFFE0

#define MINPRESSURE 10
#define MAXPRESSURE 1000

int pixel_x, pixel_y;
int backlight = 12;
char currentPage;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 365);
//declare all buttons to be used
Adafruit_GFX_Button btnLITE1, btnLITE2, btnLITE3;//Bright to dark

bool Touch_getXY(void)
{
  TSPoint p = ts.getPoint();
  bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
  if (pressed) {
    pixel_x = map(p.y, TS_MAXX, TS_MINX, tft.width(), 0);
    pixel_y = map(p.x, TS_MAXY, TS_MINY, 0, tft.height());
    //Serial.println( pixel_x);
    // Serial.println( pixel_y);
  }
  return pressed;
}
Adafruit_GFX_Button *page0_buttons[] = { 
  &btnLITE1, &btnLITE2, &btnLITE3, NULL}; //Info p==3


Adafruit_GFX_Button **active_buttons = { NULL };

bool update_button(Adafruit_GFX_Button * b, bool down) {
  b->press(down && b->contains(pixel_x, pixel_y));
  if (b->justReleased())
    b->drawButton(false);
  if (b->justPressed())
    b->drawButton(true);
  return down;
}

bool update_button_list(Adafruit_GFX_Button **pb) {
  bool down = Touch_getXY();
  for (int i = 0 ; pb[i] != NULL; i++) {
    update_button(pb[i], down);
  }
  return down;
}


void setup() {
  Serial.begin(9600);
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(1);
  pinMode(backlight, OUTPUT);
 Info();
}

void loop() {
  update_button_list(active_buttons);
  check_buttons();
}

void check_buttons() {
  if (currentPage == '0') { 
  if (btnLITE1.justPressed()) digitalWrite(backlight, 2000);//FULL brightness
    else if (btnLITE2.justPressed()) digitalWrite(backlight, 1000);//mid
    else if (btnLITE3.justPressed()) digitalWrite(backlight, 0);//DARK screen
  } 
}

void Info(){
  currentPage = '0';
  active_buttons = page0_buttons;
  tft.fillScreen(WHITE);
  btnLITE1.initButton(&tft, 55, 15, 80, 20, LIGHTGREY, LIGHTGREY, BLACK, "Back Light 1", 1);
  btnLITE1.drawButton(false);
  btnLITE2.initButton(&tft, 160, 15, 80, 20, GREY1, GREY1, BLACK, "Back Light 2", 1);
  btnLITE2.drawButton(false);
  btnLITE3.initButton(&tft, 270, 15, 80, 20, GREY2, GREY2, BLACK, "Back Light 3", 1);
  btnLITE3.drawButton(false);
}

Members

I got this working and was wondering what the max value would be for this line

if (btnLITE1.justPressed()) digitalWrite(backlight, 2000);//FULL brightness
    else if (btnLITE2.justPressed()) digitalWrite(backlight, 1000);//mid
    else if (btnLITE3.justPressed()) digitalWrite(backlight, 0);//DARK screen

The min value is set at zero but the screen is not that dark.

Thanks

I manage to find another thread with values. Seems like its 255?

If I set digitalWrite(backlight, 0); the screen goes dark and digitalWrite(backlight, 1); is bright. Nothing in between???

analogWrite(backlight, 20); is the way to go. Not digitalWrite

/*backlight test PWM = 12
  Due board
  Screen https://www.adafruit.com/product/1770
*/
#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>
MCUFRIEND_kbv tft;

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
//#define LCD_RESET A4

//Touchscreen X+ X- Y+ Y- pins
#define YP A5
#define XM A4
#define YM 10
#define XP 11
//tested as correct for new ADAFRUIT screen
#define TS_MINX 150
#define TS_MINY 90
#define TS_MAXX 900
#define TS_MAXY 800

#define BLACK       0x0000
#define BLUE        0x001F
#define CYAN        0x07FF
#define DARKCYAN    0x03EF
#define GREY1       0x8410
#define GREY2       0x4208
#define LIGHTGREY   0xC618
#define DARKGREY    0x7BEF
#define GREEN       0x07E0
#define DARKGREEN   0x03E0
#define GREENYELLOW 0xB7E0
#define MAGENTA     0xF81F
#define MAROON      0x7800
#define NAVY        0x000F
#define OLIVE       0x7BE0
#define ORANGE      0xFDA0
#define PINK        0xFC9F
#define PURPLE      0x780F
#define RED         0xF800
#define BRIGHT_RED  0xf810
#define WHITE       0xFFFF
#define YELLOW      0xFFE0

#define MINPRESSURE 10
#define MAXPRESSURE 1000

int pixel_x, pixel_y;
int backlight = 12;
char currentPage;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 365);
//declare all buttons to be used
Adafruit_GFX_Button btnLITE1, btnLITE2, btnLITE3;//Bright to dark

bool Touch_getXY(void)
{
  TSPoint p = ts.getPoint();
  bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
  if (pressed) {
    pixel_x = map(p.y, TS_MAXX, TS_MINX, tft.width(), 0);
    pixel_y = map(p.x, TS_MAXY, TS_MINY, 0, tft.height());
    //Serial.println( pixel_x);
    // Serial.println( pixel_y);
  }
  return pressed;
}
Adafruit_GFX_Button *page0_buttons[] = {
  &btnLITE1, &btnLITE2, &btnLITE3, NULL
}; 


Adafruit_GFX_Button **active_buttons = { NULL };

bool update_button(Adafruit_GFX_Button * b, bool down) {
  b->press(down && b->contains(pixel_x, pixel_y));
  if (b->justReleased())
    b->drawButton(false);
  if (b->justPressed())
    b->drawButton(true);
  return down;
}

bool update_button_list(Adafruit_GFX_Button **pb) {
  bool down = Touch_getXY();
  for (int i = 0 ; pb[i] != NULL; i++) {
    update_button(pb[i], down);
  }
  return down;
}

void setup() {
  Serial.begin(9600);
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(1);
  pinMode(backlight, OUTPUT);
  analogWrite(backlight,50);
 
  Info();
}

void loop() {
  update_button_list(active_buttons);
  check_buttons();
  }

void check_buttons() {
  if (currentPage == '0') {
    if (btnLITE1.justPressed()) analogWrite(backlight, 253);//FULL brightness
    else if (btnLITE2.justPressed()) analogWrite(backlight, 160);//mid
    else if (btnLITE3.justPressed()) analogWrite(backlight, 20);//DARK screen
  }
}

void Info() {
  currentPage = '0';
  active_buttons = page0_buttons;
  tft.fillScreen(BLACK);
  btnLITE1.initButton(&tft, 55, 15, 80, 20, LIGHTGREY, LIGHTGREY, BLACK, "Back Light 1", 1);
  btnLITE1.drawButton(false);
  btnLITE2.initButton(&tft, 160, 15, 80, 20, GREY1, GREY1, BLACK, "Back Light 2", 1);
  btnLITE2.drawButton(false);
  btnLITE3.initButton(&tft, 270, 15, 80, 20, GREY2, GREY2, BLACK, "Back Light 3", 1);
  btnLITE3.drawButton(false);
}