Last active
March 14, 2024 15:24
-
-
Save eggfly/756844138e157fba0b8728e04cda9d9c to your computer and use it in GitHub Desktop.
ESP32-MicroPython-LVGL-ILI9341-Test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ili9XXX import ili9341 | |
import lvgl as lv | |
from machine import Pin, PWM | |
def init_backlight(brightness): | |
frequency = 5000 | |
duty_cycle = int(1023 * brightness) | |
led = PWM(Pin(21), frequency) | |
led.duty(duty_cycle) | |
def init_screen(): | |
rot = 3 # 0->0, 1->90, 2->180, 3->270 | |
rotations = [0x80, 0xE0, 0x40, 0x20] | |
if rot % 2 == 0: | |
width, height = 240, 320 | |
else: | |
width, height = 320, 240 | |
disp = ili9341(mosi=13, miso=12, clk=14, dc=2, cs=15, invert=False, | |
rot=rotations[rot], width=width, height=height, | |
rst=-1, power=-1, backlight=-1) | |
def lv_draw_ui(): | |
scr = lv.obj() | |
btn = lv.button(scr) | |
btn.align(lv.ALIGN.CENTER, 0, 0) | |
label = lv.label(btn) | |
label.set_text('Hello World!') | |
lv.screen_load(scr) | |
init_backlight(0.5) | |
init_screen() | |
lv_draw_ui() | |
print('DONE!') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment