本文主要是介绍用微雪RP2040-LCD-1.28设计一款模拟电子表,带屏PICO应用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
微雪RP2040-LCD-1.28介绍
微雪RP2040-LCD-1.28 是一款国内创新设计的PICO微控制器开发板,其在较小的板型情况下,板载了1.28inch LCD、锂电池充电芯片、六轴传感器(三轴加速度与三轴陀螺仪)等外设。
屏幕及驱动板参数
LCD参数 | |||
控制芯片 | GC9A01A | 分辨率 | 240(H)RGB x 240(V) |
通信接口 | SPI | 显示尺寸 | Φ32.4mm |
显示面板 | IPS | 像素大小 | 0.135(H)x0.135(V)mm |
圆形显示器的座标问题,X轴Y轴方向
设计开始之前,我跟大家一样好像,这个圆型的屏幕,座标圆点在哪里,X,Y分别是什么方向的。其实圆形的屏幕,跟我们平时用的长方形的显示器一样,你把它想象成一块长方形的显示器,座标圆点在左下角,X轴向右,Y轴向上,超出圆形的像素不显示。
这是程序的最终运行结果
# 导入需要的库
import machine
from machine import Pin,I2C,SPI,PWM,ADC
import time
import math
import framebufI2C_SDA = 6
I2C_SDL = 7DC = 8
CS = 9
SCK = 10
MOSI = 11
RST = 12
BL = 25# 显示屏驱动类
class LCD_GC9A01A(framebuf.FrameBuffer):def __init__(self):self.width = 240self.height = 240self.cs = Pin(CS,Pin.OUT)self.rst = Pin(RST,Pin.OUT)self.cs(1)self.spi = SPI(1,100_000_000,polarity=0, phase=0,sck=Pin(SCK),mosi=Pin(MOSI),miso=None)self.dc = Pin(DC,Pin.OUT)self.dc(1)self.buffer = bytearray(self.height * self.width * 2)super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)self.init_display()self.red = 0x07E0self.green = 0x001fself.blue = 0xf800self.white = 0xffffself.fill(self.white)self.show()self.pwm = PWM(Pin(BL))self.pwm.freq(5000)def write_cmd(self, cmd):self.cs(1)self.dc(0)self.cs(0)self.spi.write(bytearray([cmd]))self.cs(1)def write_data(self, buf):self.cs(1)self.dc(1)self.cs(0)self.spi.write(bytearray([buf]))self.cs(1)def set_pwm(self,duty):self.pwm.duty_u16(duty) #max 65535def init_display(self):"""Initialize dispaly""" self.rst(1)time.sleep(0.01)self.rst(0)time.sleep(0.01)self.rst(1)time.sleep(0.05)self.write_cmd(0xEF)self.write_cmd(0xEB)self.write_data(0x14) self.write_cmd(0xFE) self.write_cmd(0xEF) self.write_cmd(0xEB)self.write_data(0x14) self.write_cmd(0x84)self.write_data(0x40) self.write_cmd(0x85)self.write_data(0xFF) self.write_cmd(0x86)self.write_data(0xFF) self.write_cmd(0x87)self.write_data(0xFF)self.write_cmd(0x88)self.write_data(0x0A)self.write_cmd(0x89)self.write_data(0x21) self.write_cmd(0x8A)self.write_data(0x00) self.write_cmd(0x8B)self.write_data(0x80) self.write_cmd(0x8C)self.write_data(0x01) self.write_cmd(0x8D)self.write_data(0x01) self.write_cmd(0x8E)self.write_data(0xFF) self.write_cmd(0x8F)self.write_data(0xFF) self.write_cmd(0xB6)self.write_data(0x00)self.write_data(0x20)self.write_cmd(0x36)self.write_data(0x98)self.write_cmd(0x3A)self.write_data(0x05) self.write_cmd(0x90)self.write_data(0x08)self.write_data(0x08)self.write_data(0x08)self.write_data(0x08) self.write_cmd(0xBD)self.write_data(0x06)self.write_cmd(0xBC)self.write_data(0x00)self.write_cmd(0xFF)self.write_data(0x60)self.write_data(0x01)self.write_data(0x04)self.write_cmd(0xC3)self.write_data(0x13)self.write_cmd(0xC4)self.write_data(0x13)self.write_cmd(0xC9)self.write_data(0x22)self.write_cmd(0xBE)self.write_data(0x11) self.write_cmd(0xE1)self.write_data(0x10)self.write_data(0x0E)self.write_cmd(0xDF)self.write_data(0x21)self.write_data(0x0c)self.write_data(0x02)self.write_cmd(0xF0) self.write_data(0x45)self.write_data(0x09)self.write_data(0x08)self.write_data(0x08)self.write_data(0x26)self.write_data(0x2A)self.write_cmd(0xF1) self.write_data(0x43)self.write_data(0x70)self.write_data(0x72)self.write_data(0x36)self.write_data(0x37) self.write_data(0x6F)self.write_cmd(0xF2) self.write_data(0x45)self.write_data(0x09)self.write_data(0x08)self.write_data(0x08)self.write_data(0x26)self.write_data(0x2A)self.write_cmd(0xF3) self.write_data(0x43)self.write_data(0x70)self.write_data(0x72)self.write_data(0x36)self.write_data(0x37) self.write_data(0x6F)self.write_cmd(0xED)self.write_data(0x1B) self.write_data(0x0B) self.write_cmd(0xAE)self.write_data(0x77)self.write_cmd(0xCD)self.write_data(0x63)self.write_cmd(0x70)self.write_data(0x07)self.write_data(0x07)self.write_data(0x04)self.write_data(0x0E) self.write_data(0x0F) self.write_data(0x09)self.write_data(0x07)self.write_data(0x08)self.write_data(0x03)self.write_cmd(0xE8)self.write_data(0x34)self.write_cmd(0x62)self.write_data(0x18)self.write_data(0x0D)self.write_data(0x71)self.write_data(0xED)self.write_data(0x70) self.write_data(0x70)self.write_data(0x18)self.write_data(0x0F)self.write_data(0x71)self.write_data(0xEF)self.write_data(0x70) self.write_data(0x70)self.write_cmd(0x63)self.write_data(0x18)self.write_data(0x11)self.write_data(0x71)self.write_data(0xF1)self.write_data(0x70) self.write_data(0x70)self.write_data(0x18)self.write_data(0x13)self.write_data(0x71)self.write_data(0xF3)self.write_data(0x70) self.write_data(0x70)self.write_cmd(0x64)self.write_data(0x28)self.write_data(0x29)self.write_data(0xF1)self.write_data(0x01)self.write_data(0xF1)self.write_data(0x00)self.write_data(0x07)self.write_cmd(0x66)self.write_data(0x3C)self.write_data(0x00)self.write_data(0xCD)self.write_data(0x67)self.write_data(0x45)self.write_data(0x45)self.write_data(0x10)self.write_data(0x00)self.write_data(0x00)self.write_data(0x00)self.write_cmd(0x67)self.write_data(0x00)self.write_data(0x3C)self.write_data(0x00)self.write_data(0x00)self.write_data(0x00)self.write_data(0x01)self.write_data(0x54)self.write_data(0x10)self.write_data(0x32)self.write_data(0x98)self.write_cmd(0x74)self.write_data(0x10)self.write_data(0x85)self.write_data(0x80)self.write_data(0x00) self.write_data(0x00) self.write_data(0x4E)self.write_data(0x00)self.write_cmd(0x98)self.write_data(0x3e)self.write_data(0x07)self.write_cmd(0x35)self.write_cmd(0x21)self.write_cmd(0x11)time.sleep(0.12)self.write_cmd(0x29)time.sleep(0.02)self.write_cmd(0x21)self.write_cmd(0x11)self.write_cmd(0x29)def show(self):self.write_cmd(0x2A)self.write_data(0x00)self.write_data(0x00)self.write_data(0x00)self.write_data(0xef)self.write_cmd(0x2B)self.write_data(0x00)self.write_data(0x00)self.write_data(0x00)self.write_data(0xEF)self.write_cmd(0x2C)self.cs(1)self.dc(1)self.cs(0)self.spi.write(self.buffer)self.cs(1)lcd = LCD_GC9A01A() # 实例化一个屏幕驱动,像素宽高为240X240
lcd.set_pwm(65535) # 设置屏幕亮度,# 清空屏幕
lcd.fill(0xFFFFFF)# 计算圆心坐标和半径
center_x = 120
center_y = 120
radius = 100# 绘制指针和秒表圆弧
while True:# 绘制圆形边框和时间文字for i in range(1, 13):angle = 2 * math.pi * i / 12 - math.pi / 2x1 = center_x + int((radius + 14) * math.cos(angle))y1 = center_y + int((radius + 14) * math.sin(angle))lcd.text(str(i), x1 - 4, y1 - 4, 0x000000)x1 = center_x + int((radius + 8) * math.cos(angle))y1 = center_y + int((radius + 8) * math.sin(angle))x2 = center_x + int((radius - 10) * math.cos(angle))y2 = center_y + int((radius - 10) * math.sin(angle))lcd.line(x1, y1, x2, y2, 0x000000)# 获取当前时间current_time = time.localtime()# 计算小时指针、分钟指针和秒针的位置hour_angle = 2 * math.pi * (current_time[3] % 12 + current_time[4] / 60) / 12 - math.pi / 2hour_x = center_x + int((radius - 50) * math.cos(hour_angle))hour_y = center_y + int((radius - 50) * math.sin(hour_angle))minute_angle = 2 * math.pi * (current_time[4] + current_time[5] / 60) / 60 - math.pi / 2minute_x = center_x + int((radius - 30) * math.cos(minute_angle))minute_y = center_y + int((radius - 30) * math.sin(minute_angle))second_angle = 2 * math.pi * (current_time[5] + current_time[6] / 1000) / 60 - math.pi / 2second_x = center_x + int((radius - 10) * math.cos(second_angle))second_y = center_y + int((radius - 10) * math.sin(second_angle))# 绘制秒表圆弧#lcd.circle(center_x, center_y, radius - 5, 0x000000, width=2, start_angle=0, end_angle=int(360 * current_time[6] / 1000))# 绘制指针lcd.line(center_x, center_y, hour_x, hour_y, 0x0000FF)lcd.line(center_x, center_y, minute_x, minute_y, 0x00FF00)lcd.line(center_x, center_y, second_x, second_y, 0xFF0000)# 刷新屏幕lcd.show()# 暂停 1秒time.sleep(1)# 清空屏幕lcd.fill(0xFFFFFF)
这篇关于用微雪RP2040-LCD-1.28设计一款模拟电子表,带屏PICO应用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!