Perfect.
If possible and if you have a time, please help me with this.
With lv_arduino(1.0) I able to use Capacitive Touch 3.5" screen/ILI9488 with FT6206.
Here is example code:
#include <lvgl.h>
#include <SPI.h>
#include <Ticker.h>
#include <TFT_eSPI.h>
#include <Adafruit_FT6206.h>
#include <OneWire.h>
#include <Wire.h>
#define BL 18
#define LVGL_TICK_PERIOD 20
Ticker tick; /* timer for interrupt handler */
TFT_eSPI tft = TFT_eSPI(); /* TFT instance */;
Adafruit_FT6206 ts = Adafruit_FT6206();
void my_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t *color_array)
{
/*TODO copy 'color_array' to the specifed coordinats of your disaply.*/
//tft.changeMode(GRAPHIC);//first we swith in graphic mode
int32_t x;
int32_t y;
for(y = y1; y <= y2; y++) {
for(x = x1; x <= x2; x++) {
/* Put a pixel to the display. For example: */
/* put_px(x, y, *color_p)*/
tft.drawPixel(x, y, color_array->full);
color_array++;
}
}
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_flush_ready();
}
bool my_tp_read(lv_indev_data_t *data)
{
/*
uint16_t tx, ty;
if (tft.touchDetect()){
tft.touchReadPixel(&tx, &ty);//read directly in pixel!
tx=tx;ty=ty;
Serial.print("x: " );
Serial.print(tx);
Serial.print(" y: " );
Serial.println(ty);
} */
//bool tp_is_pressed = false; /*TODO read here the state of toush pad*/
//if (tft.touchDetect()) {
if (ts.touched()) {
uint16_t last_x = 0;
uint16_t last_y = 0;
//tft.touchReadPixel(&last_x, &last_y);
TS_Point p = ts.getPoint();
// last_x = last_x;
// last_y = last_y;
// data->point.x = (int16_t)last_x;
// data->point.y = (int16_t)last_y;
p.x = map(p.x, 0, 320, 320, 0);
p.y = map(p.y, 0, 480, 480, 0);
data->point.x = p.y;
data->point.y = tft.height() - p.x;
data->state = LV_INDEV_STATE_PR;
} else data->state = LV_INDEV_STATE_REL;
return false; /*Return false because no moare to be read*/
}
void hal_init(void)
{
/*Initialize the display*/
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.disp_flush = my_disp_flush;
lv_disp_drv_register(&disp_drv);
/*Initialize the touch pad*/
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read = my_tp_read;
lv_indev_drv_register(&indev_drv);
/*Initialize the graphics library's tick*/
/*In a Timer call 'lv_tick_inc(1)' in every milliseconds
Or no other option call it loop */
}
void setup() {
Serial.begin(115200);
Serial.println("RA8875 start");
//initialization routine
tft.begin(); /* TFT init */
pinMode(BL, OUTPUT);
digitalWrite(BL, HIGH);
if (!ts.begin(40)) {
Serial.println("Unable to start touchscreen.");
}
else {
Serial.println("Touchscreen started.");
}
tft.setRotation(3); /* Landscape orientation */
Wire.begin();
lv_init();
hal_init();
}
void loop() {
// put your main code here, to run repeatedly:
printSplash();
while (true) {
lv_task_handler();
lv_tick_inc(5); // is not called in a Timer then call it here*/
delay(0); /*Wait a little*/
}
}
void printSplash(void) {
/* lv_obj_t *label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label, "Hello Arduino!");
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
*/
/********************
* CREATE A SCREEN
*******************/
/* Create a new screen and load it
* Screen can be created from any type object type
* Now a Page is used which is an objects with scrollable content*/
lv_obj_t * scr = lv_page_create(NULL, NULL);
lv_scr_load(scr);
/****************
* ADD A TITLE
****************/
lv_obj_t * label = lv_label_create(scr, NULL); /*First parameters (scr) is the parent*/
lv_label_set_text(label, "Object usage demo"); /*Set the text*/
lv_obj_set_x(label, 50); /*Set the x coordinate*/
/***********************
* CREATE TWO BUTTONS
***********************/
/*Create a button*/
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); /*Create a button on the currently loaded screen*/
lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, btn_rel_action); /*Set function to be called when the button is released*/
lv_obj_align(btn1, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 20); /*Align below the label*/
/*Create a label on the button (the 'label' variable can be reused)*/
label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Button 1");
/*Copy the previous button*/
lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), btn1); /*Second parameter is an object to copy*/
lv_obj_align(btn2, btn1, LV_ALIGN_OUT_RIGHT_MID, 50, 0); /*Align next to the prev. button.*/
/*Create a label on the button*/
label = lv_label_create(btn2, NULL);
lv_label_set_text(label, "Button 2");
/****************
* ADD A SLIDER
****************/
lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL); /*Create a slider*/
lv_obj_set_size(slider, lv_obj_get_width(lv_scr_act()) / 3, LV_DPI / 3); /*Set the size*/
lv_obj_align(slider, btn1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 20); /*Align below the first button*/
lv_slider_set_value(slider, 30); /*Set the current value*/
/***********************
* ADD A DROP DOWN LIST
************************/
lv_obj_t * ddlist = lv_ddlist_create(lv_scr_act(), NULL); /*Create a drop down list*/
//lv_obj_set_size(ddlist, 100, 50); /*Set the size*/
lv_obj_align(ddlist, slider, LV_ALIGN_OUT_RIGHT_TOP, 50, 0); /*Align next to the slider*/
lv_obj_set_free_ptr(ddlist, slider); /*Save the pointer of the slider in the ddlist (used in 'ddlist_action()')*/
lv_obj_set_top(ddlist, true); /*Enable to be on the top when clicked*/
lv_ddlist_set_options(ddlist, "None\nLittle\nHalf\nA lot\nAll"); /*Set the options*/
lv_ddlist_set_action(ddlist, ddlist_action); /*Set function to call on new option is chosen*/
/****************
* CREATE A CHART
****************/
lv_obj_t * chart = lv_chart_create(lv_scr_act(), NULL); /*Create the chart*/
lv_obj_set_size(chart, lv_obj_get_width(scr) / 2, lv_obj_get_width(scr) / 4); /*Set the size*/
lv_obj_align(chart, slider, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 50); /*Align below the slider*/
lv_chart_set_series_width(chart, 3); /*Set the line width*/
/*Add a RED data series and set some points*/
lv_chart_series_t * dl1 = lv_chart_add_series(chart, LV_COLOR_RED);
lv_chart_set_next(chart, dl1, 10);
lv_chart_set_next(chart, dl1, 25);
lv_chart_set_next(chart, dl1, 45);
lv_chart_set_next(chart, dl1, 80);
/*Add a BLUE data series and set some points*/
lv_chart_series_t * dl2 = lv_chart_add_series(chart, LV_COLOR_MAKE(0x40, 0x70, 0xC0));
lv_chart_set_next(chart, dl2, 10);
lv_chart_set_next(chart, dl2, 25);
lv_chart_set_next(chart, dl2, 45);
lv_chart_set_next(chart, dl2, 80);
lv_chart_set_next(chart, dl2, 75);
lv_chart_set_next(chart, dl2, 505);
}
/**
* Called when a button is released
* @param btn pointer to the released button
* @return LV_RES_OK because the object is not deleted in this function
*/
static lv_res_t btn_rel_action(lv_obj_t * btn)
{
/*Increase the button width*/
lv_coord_t width = lv_obj_get_width(btn);
lv_obj_set_width(btn, width);
Serial.println("Button released");
return LV_RES_OK;
}
/**
* Called when a new option is chosen in the drop down list
* @param ddlist pointer to the drop down list
* @return LV_RES_OK because the object is not deleted in this function
*/
static lv_res_t ddlist_action(lv_obj_t * ddlist)
{
uint16_t opt = lv_ddlist_get_selected(ddlist); /*Get the id of selected option*/
//lv_obj_t * slider = lv_obj_get_free_ptr(ddlist); /*Get the saved slider*/
lv_obj_t * slider = (lv_obj_t *) lv_obj_get_free_ptr(ddlist);
lv_slider_set_value(slider, (opt * 100) / 4); /*Modify the slider value according to the selection*/
return LV_RES_OK;
}
But, with lv_arduino(6.0), when I’m trying to compile ESP32_TFT_eSPI_Slider
I’m getting this error
‘touched’ was not declared in this scope
Thank you