1.54" LCD st7789 spi or other LCD can be used
Method and description
set_color(fg,bg): display color text RGB565: foreground view , background color
set_color(color565(r,g,b),color565(r,g,b)) rgb: 0,0,0, : foreground color , background color
RGB color mode is a color standard in the industry, which is used to obtain various colors by changing the three color channels of red, green and blue and superimposing them on each other. RGB is the color representing the three channels of red, green, and blue, and this standard includes almost all the colors that human eyesight can perceive, and is one of the most widely used color systems.
RGB565
Each pixel is represented by 16 bits and occupies 2 bytes, and the RGB components use 5 bits, 6 bits, and 5 bits respectively.
Example program
main.py
Code: Select all
import time
from pyb import SPI,Pin,Timer,delay
from ztst7789class import ST7789
import tt32
from car import car
from time import sleep_us,ticks_us,sleep
# Define pin, when low, the indicator is on.
xun1 = Pin(("C3"),Pin.IN)
xun4 = Pin(("C2"),Pin.IN)
xun3 = Pin(("C1"),Pin.IN)
xun2 = Pin(("C0"),Pin.IN)
# ---------TFT pin definition
RES = Pin('C4')
BLK = Pin('B10')
DC = Pin('C5')
CS = Pin('B11')
SCL = Pin('A5')
TFT_MISO_PIN = Pin('A6')
SDA = Pin('A7')
bl = Pin(BLK, Pin.OUT)
def lcdinit(): #Initialize function
global LCD
bl.value(1) #Screen backlight on
spi = SPI(1,SPI.MASTER,baudrate=7800000,polarity=0,phase=0)
LCD = ST7789(spi, cs=Pin(CS), dc=Pin(DC), rst=RES)
def color565(r, g, b): #255 255 255 255
return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3
lcdinit() #initialize
LCD.erase()
LCD.set_font(tt32)
while True:
# display color text foreground red 0xF800 black background is 0x0000
LCD.set_color(0xd8a7,0x0)
LCD.set_font(tt32)
LCD.set_pos(0,10)
LCD.print('xianyujun')
# foreground red, background green
LCD.set_color(color565(255,0,0),color565(0,255,0,))
LCD.set_font(tt32)
LCD.set_pos(0,100)
LCD.print('xianyujun')