官术网_书友最值得收藏!

Writing an ESP32 program

To write our program, we need to follow these steps:

  1. Modify the tft_demo.c file from the TFT library for ESP32. For this, we will use the circle_demo() function, as written here:
static void circle_demo()
{
int x, y, r, n;
//In the upper part of the LCD display print the message “CIRCLE DEMO
disp_header("CIRCLE DEMO");
  1. Now draw some random circles on the LCD display using the TFT_drawCircle function. The circles will be randomly positioned on the screen and will have a random color with the help of the function random_color(). After that, the bottom header will be updated with the number of drawn circles (for example, 208 CIRCLES).


uint32_t end_time = clock() + GDEMO_TIME;
n = 0;
while ((clock() < end_time) && (Wait(0))) {
x = rand_interval(8, dispWin.x2-8);
y = rand_interval(8, dispWin.y2-8);
if (x < y) r = rand_interval(2, x/2);
else r = rand_interval(2, y/2);
TFT_drawCircle(x,y,r,random_color());
n++;
}
sprintf(tmp_buff, "%d CIRCLES", n);
update_header(NULL, tmp_buff);
Wait(-GDEMO_INFO_TIME);
  1. Now is the time to not only draw some circles but also fill to them with colors using the function TFT_fillCircle(). In the end, using the same values for x, y and r but different random_color() values, the circles will have a different filling and a different edge color.  


update_header("FILLED CIRCLE", "");
TFT_fillWindow(TFT_BLACK);
end_time = clock() + GDEMO_TIME;
n = 0;
while ((clock() < end_time) && (Wait(0))) {
x = rand_interval(8, dispWin.x2-8);
y = rand_interval(8, dispWin.y2-8);
if (x < y) r = rand_interval(2, x/2);
else r = rand_interval(2, y/2);
TFT_fillCircle(x,y,r,random_color());
TFT_drawCircle(x,y,r,random_color());
n++;
}
sprintf(tmp_buff, "%d CIRCLES", n);
update_header(NULL, tmp_buff);
Wait(-GDEMO_INFO_TIME);
}
  1. Next, modify the tft_demo() function that calls the circle_demo() function:
void tft_demo() {

...

// demo
disp_header("Welcome to ESP32");
circle_demo();


while (1) {
// do nothing
}
}
  1. Since we will use some components that are located on <project>/components, we should tell the compiler to include these components. We will add the component.mk file with our components included, as follows:
COMPONENT_SRCDIRS := . 
COMPONENT_ADD_INCLUDEDIRS := .
  1. For the Makefile file, we can write these scripts as follows:
PROJECT_NAME := lcddemo

EXTRA_CFLAGS += --save-temps

include $(IDF_PATH)/make/project.mk
  1. Save all files before configuring our project to compile and flash our program into the ESP32 board.

Now that we've created the program, let's configure our board.

主站蜘蛛池模板: 合肥市| 新田县| 呼伦贝尔市| 龙山县| 朝阳区| 开阳县| 永德县| 南郑县| 吐鲁番市| 南郑县| 那坡县| 鹤庆县| 双柏县| 云和县| 长兴县| 微博| 乌拉特前旗| 秦皇岛市| 中超| 湖南省| 囊谦县| 江城| 湖南省| 兴隆县| 吉隆县| 全南县| 景宁| 芜湖县| 商丘市| 扶风县| 肇源县| 双桥区| 和顺县| 海安县| 涪陵区| 普兰店市| 陆川县| 陕西省| 武清区| 桃源县| 铜梁县|