当前位置: 代码迷 >> 综合 >> 【Luat-esp32】2.2 lvgl显示button
  详细解决方案

【Luat-esp32】2.2 lvgl显示button

热度:53   发布时间:2023-12-05 20:30:47.0

前言

本文显示lvgl按键demo。

硬件连接

https://blog.csdn.net/qq_38091632/article/details/122641881
在这里插入图片描述

在这里插入图片描述

代码

来源:https://github.com/dreamcmi/LuatOS-ESP32/blob/master/demo/lvgl/main.lua

main.lua

--- 模块功能:lvgldemo_button
-- @module lvgl
-- @author Dozingfiretruck,youkai
-- @release 2022.01.25-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "lvgldemo"
VERSION = "1.0.0"log.info("main", PROJECT, VERSION)-- sys库是标配
_G.sys = require("sys")
require("esp32_st7735")log.info("hello luatos")init_esp32_st7735 ()
log.info("lvgl", lvgl.init(128,160))
lvgl.disp_set_bg_color(nil, 0xFFFFFF)
local scr = lvgl.obj_create(nil, nil)
local btn = lvgl.btn_create(scr)
lvgl.obj_align(btn, lvgl.scr_act(), lvgl.ALIGN_CENTER, 0, 0)
local label = lvgl.label_create(btn)
lvgl.label_set_text(label, "LuatOS!")
lvgl.scr_load(scr)sys.taskInit(function()while 1 dosys.wait(1000)end
end)-- 用户代码已结束---------------------------------------------
-- 结尾总是这一句
sys.run()
-- sys.run()之后后面不要加任何语句!!!!!

esp32_st7735.lua

-- 1. display: st735
function init_esp32_st7735 ()-- spi test ok-- spi clk is io2, cs is IO7spi_lcd = spi.deviceSetup(2,7,0,0,8,20000000,spi.MSB,1,1)log.info("SPI OK")log.info("lcd.init",-- st7735 + esp32lcd.init("st7735",{
    port = "device",pin_dc = 6, pin_pwr = 11,pin_rst = 10,direction = 0,w = 128,h = 160,xoffset = 0,yoffset = 0},spi_lcd))log.info("LCD OK")
endfunction display_line ()log.info("lcd.drawLine", lcd.drawLine(20,20,150,20,0x001F))log.info("lcd.drawRectangle", lcd.drawRectangle(20,40,120,70,0xF800))log.info("lcd.drawCircle", lcd.drawCircle(50,50,20,0x0CE0))-- sys.wait(1500)log.info("display demo")
endfunction display_str ()lcd.setFont(lcd.font_opposansm12)lcd.drawStr(40,10,"drawStr")lcd.setFont(lcd.font_opposansm16_chinese)lcd.drawStr(40,40,"drawStr测试")
end

结果

在这里插入图片描述

小结

本文运行了lvgl的demo,显示按键,后续再尝试显示图片。

  相关解决方案