Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #define LV_COLOR_16_SWAP 0
- #include <TFT_eSPI.h>
- #include <lvgl.h>
- // Display & LVGL setup
- TFT_eSPI tft = TFT_eSPI();
- static lv_disp_draw_buf_t draw_buf;
- static lv_color_t buf[LV_HOR_RES_MAX * 10];
- lv_obj_t *table;
- // LVGL Display Flush Callback
- void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
- uint16_t w = area->x2 - area->x1 + 1;
- uint16_t h = area->y2 - area->y1 + 1;
- tft.startWrite();
- tft.setAddrWindow(area->x1, area->y1, w, h);
- tft.pushColors((uint16_t *)&color_p->full, w * h, true);
- tft.endWrite();
- lv_disp_flush_ready(disp);
- }
- void setup() {
- // pinMode(TFT_BL, OUTPUT);
- // digitalWrite(TFT_BL, LOW);
- Serial.begin(115200);
- delay(100);
- tft.begin();
- tft.setRotation(1);
- tft.fillScreen(TFT_BLACK);
- delay(50);
- //digitalWrite(TFT_BL, HIGH);
- // Initialize LVGL
- lv_init();
- memset(buf, 0x00, sizeof(buf));
- //lv_refr_now(NULL);
- lv_disp_draw_buf_init(&draw_buf, buf, NULL, LV_HOR_RES_MAX * 10);
- // Setup LVGL Display Driver
- static lv_disp_drv_t disp_drv;
- lv_disp_drv_init(&disp_drv);
- disp_drv.hor_res = 320;
- disp_drv.ver_res = 240;
- disp_drv.flush_cb = my_disp_flush;
- disp_drv.draw_buf = &draw_buf;
- lv_disp_drv_register(&disp_drv);
- lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(30, 30, 30), LV_PART_MAIN);
- lv_obj_t *label = lv_label_create(lv_scr_act());
- lv_label_set_text(label, "Test");
- lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
- lv_obj_set_style_text_color(label, lv_color_white(), LV_PART_MAIN | LV_STATE_DEFAULT);
- }
- void loop() {
- delay(500);
- lv_timer_handler();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement