Advertisement
espd

flicker

May 15th, 2025
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <Arduino.h>
  2. #define LV_COLOR_16_SWAP 0
  3. #include <TFT_eSPI.h>
  4. #include <lvgl.h>
  5.  
  6. // Display & LVGL setup
  7. TFT_eSPI tft = TFT_eSPI();
  8. static lv_disp_draw_buf_t draw_buf;
  9. static lv_color_t buf[LV_HOR_RES_MAX * 10];
  10. lv_obj_t *table;
  11.  
  12. // LVGL Display Flush Callback
  13. void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
  14.   uint16_t w = area->x2 - area->x1 + 1;
  15.   uint16_t h = area->y2 - area->y1 + 1;
  16.   tft.startWrite();
  17.   tft.setAddrWindow(area->x1, area->y1, w, h);
  18.   tft.pushColors((uint16_t *)&color_p->full, w * h, true);
  19.   tft.endWrite();
  20.   lv_disp_flush_ready(disp);
  21. }
  22.  
  23. void setup() {
  24.  // pinMode(TFT_BL, OUTPUT);
  25.  // digitalWrite(TFT_BL, LOW);  
  26.   Serial.begin(115200);
  27.   delay(100);
  28.  
  29.   tft.begin();
  30.   tft.setRotation(1);
  31.   tft.fillScreen(TFT_BLACK);
  32.  
  33.   delay(50);
  34.   //digitalWrite(TFT_BL, HIGH);
  35.  
  36.   // Initialize LVGL
  37.   lv_init();
  38.  
  39.   memset(buf, 0x00, sizeof(buf));
  40.   //lv_refr_now(NULL);
  41.   lv_disp_draw_buf_init(&draw_buf, buf, NULL, LV_HOR_RES_MAX * 10);
  42.  
  43.   // Setup LVGL Display Driver
  44.   static lv_disp_drv_t disp_drv;
  45.   lv_disp_drv_init(&disp_drv);
  46.   disp_drv.hor_res = 320;
  47.   disp_drv.ver_res = 240;
  48.   disp_drv.flush_cb = my_disp_flush;
  49.   disp_drv.draw_buf = &draw_buf;
  50.   lv_disp_drv_register(&disp_drv);
  51.  
  52.   lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(30, 30, 30), LV_PART_MAIN);
  53.  
  54.   lv_obj_t *label = lv_label_create(lv_scr_act());
  55.   lv_label_set_text(label, "Test");  
  56.   lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
  57.   lv_obj_set_style_text_color(label, lv_color_white(), LV_PART_MAIN | LV_STATE_DEFAULT);
  58. }
  59.  
  60. void loop() {
  61.   delay(500);
  62.   lv_timer_handler();
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement