class ST7735S(): def __init__(self, width, hight): self.lcdlog = log.basicConfig() self.lcdlog = log.getLogger("LCD") self.lcdlog.setLevel(log.DEBUG) self.lcd = LCD() self.lcd_w = width self.lcd_h = hight self.st7735s_init_data = ( 0, 0, 0x11, 2, 0, 120, 0, 3, 0xb1, 1, 1, 0x01, 1, 1, 0x08, 1, 1, 0x05, 0, 3, 0xb2, 1, 1, 0x05, 1, 1, 0x3c, 1, 1, 0x3c, 0, 6, 0xb3, 1, 1, 0x05, 1, 1, 0x3c, 1, 1, 0x3c, 1, 1, 0x05, 1, 1, 0x3c, 1, 1, 0x3c, 0, 1, 0xb4, 1, 1, 0x03, 0, 3, 0xc0, 1, 1, 0x28, 1, 1, 0x08, 1, 1, 0x04, 0, 1, 0xc1, 1, 1, 0xc0, 0, 2, 0xc2, 1, 1, 0x0d, 1, 1, 0x00, 0, 2, 0xc3, 1, 1, 0x8d, 1, 1, 0x2a, 0, 2, 0xc4, 1, 1, 0x8d, 1, 1, 0xee, 0, 1, 0xc5, 1, 1, 0x12, 0, 1, 0x36, 1, 1, 0xA0, 0, 16, 0xe0, 1, 1, 0x04, 1, 1, 0x22, 1, 1, 0x07, 1, 1, 0x0a, 1, 1, 0x2e, 1, 1, 0x30, 1, 1, 0x25, 1, 1, 0x2a, 1, 1, 0x28, 1, 1, 0x26, 1, 1, 0x2e, 1, 1, 0x3a, 1, 1, 0x00, 1, 1, 0x01, 1, 1, 0x03, 1, 1, 0x13, 0, 16, 0xe1, 1, 1, 0x04, 1, 1, 0x16, 1, 1, 0x06, 1, 1, 0x0d, 1, 1, 0x2d, 1, 1, 0x26, 1, 1, 0x23, 1, 1, 0x27, 1, 1, 0x27, 1, 1, 0x25, 1, 1, 0x2d, 1, 1, 0x3b, 1, 1, 0x00, 1, 1, 0x01, 1, 1, 0x04, 1, 1, 0x13, 0, 1, 0x3a, 1, 1, 0x05, 0, 1, 0x35, 1, 1, 0x00, 0, 0, 0x29, 1, 0, 0x2c, ) self.st7735s_invalid_data = ( 0, 4, 0x2A, 1, 1, XSTART_H, 1, 1, XSTART_L, 1, 1, XEND_H, 1, 1, XEND_L, 0, 4, 0x2B, 1, 1, YSTART_H, 1, 1, YSTART_L, 1, 1, YEND_H, 1, 1, YEND_L, 0, 0, 0x2C, ) lcd_clk = 26000 lcd_init_data = bytearray(self.st7735s_init_data) lcd_invalid = bytearray(self.st7735s_invalid_data) ret = self.lcd.lcd_init(lcd_init_data, self.lcd_w, self.lcd_h, lcd_clk, 1, 4, 0, lcd_invalid, None, None, None) self.lcdlog.info('lcd.lcd_init ret = {}'.format(ret)) self.lcdlog.info('lcd.lcd_clk = {}'.format(lcd_clk)) '''清屏,设置白色''' self.lcd.lcd_clear(0xFFFF) ''' 单个字符显示,包括汉字和ASCII x - x轴坐标 y - y轴坐标 xsize - 字体宽度 ysize - 字体高度 ch_buf - 存放汉字字模的元组或者列表 fc - 字体颜色,RGB565 bc - 背景颜色,RGB565 ''' def lcd_show_char(self, x, y, xsize, ysize, ch_buf, fc, bc): rgb_buf = [] t1 = xsize // 8 t2 = xsize % 8 if t2 != 0: xsize = (t1 + 1) * 8 for i in range(0, len(ch_buf)): for j in range(0, 8): if (ch_buf[i] << j) & 0x80 == 0x00: rgb_buf.append(bc & 0xff) rgb_buf.append(bc >> 8) else: rgb_buf.append(fc & 0xff) rgb_buf.append(fc >> 8) self.lcd.lcd_write(bytearray(rgb_buf), x, y, x + xsize - 1, y + ysize - 1) ''' ASCII字符显示,目前支持8x16、16x24的字体大小, 如果需要其他字体大小需要自己增加对应大小的字库数据,并 在下面函数中增加这个对应字库的字典。 x - x轴显示起点 y - y轴显示起点 xsize - 字体宽度 ysize - 字体高度 ch - 待显示的ASCII字符 fc - 字体颜色,RGB565 bc - 背景颜色,RGB565 ''' def lcd_show_ascii(self, x, y, xsize, ysize, ch, fc, bc): ascii_dict = {} if xsize == 8 and ysize == 16: ascii_dict = fonts.ascii_8x16_dict elif xsize == 16 and ysize == 24: ascii_dict = fonts.ascii_16x24_dict for key in ascii_dict: if ch == key: self.lcd_show_char(x, y, xsize, ysize, ascii_dict[key], fc, bc) ''' 显示字符串,目前支持8x16的字体大小, 如果需要其他字体大小需要自己增加对应大小的字库数据,并 在lcd_show_ascii函数中增加这个对应字库的字典。 x - x轴坐标 y - y轴坐标 xsize - 字体宽度 ysize - 字体高度 str - 待显示的 ASCII 字符串 fc - 字体颜色,RGB565 bc - 背景颜色,RGB565 ''' def lcd_show_ascii_str(self, x, y, xsize, ysize, str, fc, bc): xs = x ys = y if (len(str) * xsize + x) > self.lcd_w: raise Exception('Display out of range') for ch in str: self.lcd_show_ascii(xs, ys, xsize, ysize, ch, fc, bc) xs += xsize ''' 汉字显示,目前支持16x16、16x24、24x24的字体大小, 如果需要其他字体大小需要自己增加对应大小的字库数据,并 在下面函数中增加这个对应字库的字典。 x - x轴显示起点 y - y轴显示起点 xsize - 字体宽度 ysize - 字体高度 ch - 待显示的ASCII字符 fc - 字体颜色,RGB565 bc - 背景颜色,RGB565 ''' def lcd_show_chinese(self, x, y, xsize, ysize, ch, fc, bc): hanzi_dict = {} if xsize == 16 and ysize == 16: hanzi_dict = fonts.hanzi_16x16_dict elif xsize == 16 and ysize == 24: hanzi_dict = fonts.hanzi_16x24_dict elif xsize == 24 and ysize == 24: hanzi_dict = fonts.hanzi_24x24_dict for key in hanzi_dict: if ch == key: self.lcd_show_char(x, y, xsize, ysize, hanzi_dict[key], fc, bc) ''' 汉字字符串显示,目前支持16x16的字体大小, 如果需要其他字体大小需要自己增加对应大小的字库数据,并 在lcd_show_chinese函数中增加这个对应字库的字典。 x - x轴坐标 y - y轴坐标 xsize - 字体宽度 ysize - 字体高度 str - 待显示的多个汉字 fc - 字体颜色,RGB565 bc - 背景颜色,RGB565 ''' def lcd_show_chinese_str(self, x, y, xsize, ysize, str, fc, bc): xs = x ys = y # print('chstrlen={}, w={}'.format(len(str), self.lcd_w)) if (len(str) / 3 * xsize + x) > self.lcd_w: raise Exception('Display out of range') for i in range(0, len(str), 3): index = i + 3 ch = str[i:index] self.lcd_show_chinese(xs, ys, xsize, ysize, ch, fc, bc) xs += xsize ''' 图片显示 如果图片宽高小于80x80,可直接该函数一次性写入并显示 image_data - 存放待显示图片的RGB数据 x - x轴显示起点 y - y轴显示起点 width - 图片宽度 heigth - 图片高度 ''' def lcd_show_image(self, image_data, x, y, width, heigth): self.lcd.lcd_write(bytearray(image_data), x, y, x + width - 1, y + heigth - 1) ''' 图片显示 如果图片宽高大于80x80,用该函数来分段写入显示,分段写入原理如下: 以要显示图片的宽度为固定值,将待显示的图片分成若干宽高为 width * h 大小的图片,最后一块高度不足h的按实际高度计算, h为分割后每个图片的高度,可由用户通过参数 h 指定,h的值应该满足关系: width * h * 2 < 4096 path - 存放图片数据的txt文件路径,包含文件名,如 '/usr/image.txt' x - x轴显示起点 y - y轴显示起点 width - 图片宽度 heigth - 图片高度 h - 分割后每个图片的高度 ''' def lcd_show_image_file(self, path, x, y, width, heigth, h): image_data = [] read_n = 0 # 已经读取的字节数 byte_n = 0 # 字节数 xs = x ys = y h_step = h # 按高度h_step个像素点作为步长 h1 = heigth // h_step # 当前图片按h_step大小分割,可以得到几个 width * h_step 大小的图片 h2 = heigth % h_step # 最后剩下的一块 大小不足 width * h_step 的图片的实际高度 # print('h1 = {}, h2 = {}'.format(h1, h2)) with open(path, "r", encoding='utf-8') as fd: # for line in fd.readlines(): end = '' while not end: line = fd.readline() if line == '': end = 1 else: curline = line.strip('\r\n').strip(',').split(',') for i in curline: byte_n += 1 read_n += 1 image_data.append(int(i)) if h1 > 0 and byte_n == width * h_step * 2: self.lcd_show_image(image_data, xs, ys, width, h_step) image_data = [] ys = ys + h_step h1 -= 1 byte_n = 0 # print('image_data len = {}'.format(len(image_data))) elif h1 == 0 and read_n == width * heigth * 2: if h2 != 0: self.lcd_show_image(image_data, xs, ys, width, h2) ''' 将24位色转换位16位色 如红色的24位色为0xFF0000,则r=0xFF,g=0x00,b=0x00, 将r、g、b的值传入下面函数即可得到16位相同颜色数据 ''' def get_rgb565_color(self, r, g, b): return ((r << 8) & 0xF800) | ((g << 3) & 0x07E0) | ((b >> 3) & 0x001F)
def __init__(self, width, hight): self.lcdlog = log.basicConfig() self.lcdlog = log.getLogger("LCD") self.lcdlog.setLevel(log.DEBUG) self.lcd = LCD() self.lcd_w = width self.lcd_h = hight self.st7735s_init_data = ( 0, 0, 0x11, 2, 0, 120, 0, 3, 0xb1, 1, 1, 0x01, 1, 1, 0x08, 1, 1, 0x05, 0, 3, 0xb2, 1, 1, 0x05, 1, 1, 0x3c, 1, 1, 0x3c, 0, 6, 0xb3, 1, 1, 0x05, 1, 1, 0x3c, 1, 1, 0x3c, 1, 1, 0x05, 1, 1, 0x3c, 1, 1, 0x3c, 0, 1, 0xb4, 1, 1, 0x03, 0, 3, 0xc0, 1, 1, 0x28, 1, 1, 0x08, 1, 1, 0x04, 0, 1, 0xc1, 1, 1, 0xc0, 0, 2, 0xc2, 1, 1, 0x0d, 1, 1, 0x00, 0, 2, 0xc3, 1, 1, 0x8d, 1, 1, 0x2a, 0, 2, 0xc4, 1, 1, 0x8d, 1, 1, 0xee, 0, 1, 0xc5, 1, 1, 0x12, 0, 1, 0x36, 1, 1, 0xA0, 0, 16, 0xe0, 1, 1, 0x04, 1, 1, 0x22, 1, 1, 0x07, 1, 1, 0x0a, 1, 1, 0x2e, 1, 1, 0x30, 1, 1, 0x25, 1, 1, 0x2a, 1, 1, 0x28, 1, 1, 0x26, 1, 1, 0x2e, 1, 1, 0x3a, 1, 1, 0x00, 1, 1, 0x01, 1, 1, 0x03, 1, 1, 0x13, 0, 16, 0xe1, 1, 1, 0x04, 1, 1, 0x16, 1, 1, 0x06, 1, 1, 0x0d, 1, 1, 0x2d, 1, 1, 0x26, 1, 1, 0x23, 1, 1, 0x27, 1, 1, 0x27, 1, 1, 0x25, 1, 1, 0x2d, 1, 1, 0x3b, 1, 1, 0x00, 1, 1, 0x01, 1, 1, 0x04, 1, 1, 0x13, 0, 1, 0x3a, 1, 1, 0x05, 0, 1, 0x35, 1, 1, 0x00, 0, 0, 0x29, 1, 0, 0x2c, ) self.st7735s_invalid_data = ( 0, 4, 0x2A, 1, 1, XSTART_H, 1, 1, XSTART_L, 1, 1, XEND_H, 1, 1, XEND_L, 0, 4, 0x2B, 1, 1, YSTART_H, 1, 1, YSTART_L, 1, 1, YEND_H, 1, 1, YEND_L, 0, 0, 0x2C, ) lcd_clk = 26000 lcd_init_data = bytearray(self.st7735s_init_data) lcd_invalid = bytearray(self.st7735s_invalid_data) ret = self.lcd.lcd_init(lcd_init_data, self.lcd_w, self.lcd_h, lcd_clk, 1, 4, 0, lcd_invalid, None, None, None) self.lcdlog.info('lcd.lcd_init ret = {}'.format(ret)) self.lcdlog.info('lcd.lcd_clk = {}'.format(lcd_clk)) '''清屏,设置白色''' self.lcd.lcd_clear(0xFFFF)
def lcd_init(): lcd = LCD() # Create a LCD object lcd.light(True) # Open the backlight lcd.set_color(lcd.WHITE, lcd.BLACK) # Set background color and foreground color lcd.fill(lcd.WHITE) # Fill the entire LCD with white lcd.text("0000-00-00", 10, 0, 24) lcd.line(0, 25, 239, 25) lcd.text("City: N/A", 10, 105, 24) # prints the string at 32 font size at position (0, 48) lcd.text("Humidity: N/A", 10, 135, 24) lcd.text("Temp: N/A", 10, 165, 24) lcd.show_bmp(45, 87, "pictures/weather.bmp") lcd.show_bmp(5, 238, "pictures/micropython.bmp") lcd.show_bmp(210, 20, "pictures/wifi_week.bmp") return lcd
def __init__(self, width, hight): self.lcdlog = log.basicConfig() self.lcdlog = log.getLogger("LCD") self.lcdlog.setLevel(log.DEBUG) self.lcd = LCD() self.lcd_w = width self.lcd_h = hight self.st7789v_init_data = ( 2, 1, 120, 0, 0, 0x11, 2, 1, 120, 0, 1, 0x36, 1, 1, 0x00, 0, 1, 0x3A, 1, 1, 0x05, 0, 0, 0x21, 0, 5, 0xB2, 1, 1, 0x05, 1, 1, 0x05, 1, 1, 0x00, 1, 1, 0x33, 1, 1, 0x33, 0, 1, 0xB7, 1, 1, 0x23, 0, 1, 0xBB, 1, 1, 0x22, 0, 1, 0xC0, 1, 1, 0x2C, 0, 1, 0xC2, 1, 1, 0x01, 0, 1, 0xC3, 1, 1, 0x13, 0, 1, 0xC4, 1, 1, 0x20, 0, 1, 0xC6, 1, 1, 0x0F, 0, 2, 0xD0, 1, 1, 0xA4, 1, 1, 0xA1, 0, 1, 0xD6, 1, 1, 0xA1, 0, 14, 0xE0, 1, 1, 0x70, 1, 1, 0x06, 1, 1, 0x0C, 1, 1, 0x08, 1, 1, 0x09, 1, 1, 0x27, 1, 1, 0x2E, 1, 1, 0x34, 1, 1, 0x46, 1, 1, 0x37, 1, 1, 0x13, 1, 1, 0x13, 1, 1, 0x25, 1, 1, 0x2A, 0, 14, 0xE1, 1, 1, 0x70, 1, 1, 0x04, 1, 1, 0x08, 1, 1, 0x09, 1, 1, 0x07, 1, 1, 0x03, 1, 1, 0x2C, 1, 1, 0x42, 1, 1, 0x42, 1, 1, 0x38, 1, 1, 0x14, 1, 1, 0x14, 1, 1, 0x27, 1, 1, 0x2C, 0, 0, 0x29, 0, 1, 0x36, 1, 1, 0x00, 0, 4, 0x2a, 1, 1, 0x00, 1, 1, 0x00, 1, 1, 0x00, 1, 1, 0xef, 0, 4, 0x2b, 1, 1, 0x00, 1, 1, 0x00, 1, 1, 0x00, 1, 1, 0xef, 0, 0, 0x2c, ) self.st7789v_invalid_data = ( 0, 4, 0x2a, 1, 1, XSTART_H, 1, 1, XSTART_L, 1, 1, XEND_H, 1, 1, XEND_L, 0, 4, 0x2b, 1, 1, YSTART_H, 1, 1, YSTART_L, 1, 1, YEND_H, 1, 1, YEND_L, 0, 0, 0x2c, ) ret = self.lcd.lcd_init(bytearray(self.st7789v_init_data), self.lcd_w, self.lcd_h, 13000, 1, 4, 0, bytearray(self.st7789v_invalid_data), None, None, None) self.lcdlog.info('lcd.lcd_init ret = {}'.format(ret)) '''清屏,设置白色''' self.lcd.lcd_clear(0xFFFF)
from machine import LCD, Sprite import time, math DEG2RAD = 0.0174532925 lcd = LCD() lcd.fillScreen(lcd.color.BLACK) # DRAW CIRCLE SEGMENTS # x,y == coords of centre of circle # start_angle = 0 - 359 # sub_angle = 0 - 360 = subtended angle # r = radius # colour = 16 bit colour value def fillSegment(x, y, startAngle, subAngle, r, color): # Calculate first pair of coordinates for segment start sx = math.cos((startAngle - 90) * DEG2RAD) sy = math.sin((startAngle - 90) * DEG2RAD) x1 = sx * r + x y1 = sy * r + y # Draw colour blocks every inc degrees for i in range(startAngle, startAngle + subAngle, 1): # Calculate pair of coordinates for segment end x2 = math.cos((i + 1 - 90) * DEG2RAD) * r + x y2 = math.sin((i + 1 - 90) * DEG2RAD) * r + y lcd.fillTriangle(int(x1), int(y1), int(x2), int(y2), x, y, color) # Copy segment end to segment start for next segment
from machine import LCD lcd = LCD() st7735s_init_data = ( 0, 0, 0x11, 2, 0, 120, 0, 3, 0xb1, 1, 1, 0x01, 1, 1, 0x08, 1, 1, 0x05, 0, 3, 0xb2, 1, 1, 0x05, 1, 1,
from machine import ADC, Pin, Map, LCD, Sprite # include ADC, Pin, Map, LCD and Sprite functions from machine module import time, math # include time and math module adc = ADC(Pin(Map.WIO_MIC)) # create ADC on built-in Mic Pin WINDOW_SIZE = 50 # amount of previous signal entries that can be averaged together # set variables to 0 INDEX = 0 VALUE = 0 SUM = 0 AVERAGED = 0 READINGS = [0] * WINDOW_SIZE dB = 0 tft = LCD() # LCD initialization tft.setRotation(3) # set screen rotation spr = Sprite(tft) # initialize buffer spr.createSprite(320, 75) # create buffer ltx = 0 # saved x coordinate of bottom of needle osx = 160 # saved x coordinate osy = 160 # saved y coordinate updateTime = 0 # time for next update # create function to draw all graphics on LCD def analogMeter(): tft.fillScreen(tft.color.YELLOW) # set background color tft.fillRect(5, 3, 310, 158, tft.color.WHITE) # set meter box color tft.drawRect(5, 3, 310, 158, tft.color.BLACK) # draw border line
import time, random from machine import LCD, Sprite, Pin, Map lcd = LCD() spr = Sprite(lcd) # Pins setup LEFT = Pin(Map.WIO_5S_LEFT, Pin.IN, Pin.PULL_UP) RIGHT = Pin(Map.WIO_5S_RIGHT, Pin.IN, Pin.PULL_UP) UP = Pin(Map.WIO_5S_UP, Pin.IN, Pin.PULL_UP) DOWN = Pin(Map.WIO_5S_DOWN, Pin.IN, Pin.PULL_UP) APressed = Pin(Map.WIO_KEY_C, Pin.IN, Pin.PULL_UP) BPressed = Pin(Map.WIO_KEY_A, Pin.IN, Pin.PULL_UP) def newNum(board): xrand = random.randint(0, 3) yrand = random.randint(0, 3) while (board[xrand][yrand] > 0): xrand = random.randint(0, 3) yrand = random.randint(0, 3) board[xrand][yrand] = random.randint(1, 2) def showBoard(board): spr.createSprite(220, 100) # 2048 game size spr.fillScreen(lcd.color.BLACK) spr.setTextSize(3) x = 20 y = 2 spaceing = 25
from machine import LCD import time, math M_SIZE = 1.3333 LOOP_PERIOD = 35 ltx = 0 osx = M_SIZE * 120 osy = M_SIZE * 120 updateTime = 0 old_analog = -999 d = 0 tft = LCD() tft.fillScreen(tft.color.BLACK) def valmap(value, istart, istop, ostart, ostop): return ostart + (ostop - ostart) * ((value - istart) / (istop - istart)) def plotNeedle(value, ms_delay): global old_analog global osx, osy, ltx tft.setTextColor(tft.color.BLACK, tft.color.WHITE) if (value < -10): value = -10 # Limit value to emulate needle end stops if (value > 110): value = 110
def draw(self): lcd = LCD() lcd.fillScreen(LCD.color.BLACK) lcd.setTextColor(LCD.color.WHITE, LCD.color.DARKGREY) if IS_VIRTUAL_MACHINE: lcd.keyCallback = self.keyCallback while True: self.drawMenuButton(lcd, KeyMap.WIO_KEY_A, "CHECK", 0) self.drawMenuButton(lcd, KeyMap.WIO_KEY_B, "NEXT", 1) self.drawMenuButton(lcd, KeyMap.WIO_KEY_C, "RESET", 2) lcd.setTextColor(LCD.color.WHITE, LCD.color.BLACK) lcd.setTextSize(2) lcd.drawString("13 * 5 + 8 = ?", 50, 70) lcd.setTextSize(1) lcd.drawLine(int(60), int(0), int(60), int(20), LCD.color.WHITE) lcd.drawLine(int(120), int(0), int(120), int(20), LCD.color.WHITE) lcd.drawLine(int(180), int(0), int(180), int(20), LCD.color.WHITE) lcd.drawLine(int(0), int(20), int(180), int(20), LCD.color.WHITE) time.sleep(self.MAIN_LOOP_DELAY)
from machine import LCD tft = LCD() tft.fillScreen(tft.color.BLACK) tft.drawPixel(50, 50, tft.color.WHITE) tft.drawLine(10, 1, 100, 10, tft.color.WHITE) tft.drawRoundRect(110, 70, 100, 100, 10, tft.color.GREEN) tft.fillRoundRect(220, 100, 10, 20, 2, tft.color.GREEN) tft.drawTriangle(160, 70, 60, 170, 260, 170, tft.color.BLUE) tft.drawNumber(70, 20, 100) tft.drawFloat(3.1415, 300, 400) tft.drawChar(10, 10, 2, 64) tft.setTextColor(tft.color.RED) tft.setTextSize(1) tft.drawString("Hello world!", 230, 210) tft.setTextSize(2) tft.drawString("H", 200, 210) tft.drawCircle(100, 100, 50, tft.color.WHITE)
def main(): lcd = LCD() lcd.light(True) lcd.set_color(lcd.WHITE, lcd.BLACK) image_buf = bytearray([ 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFD, 0XFF, 0XDA, 0XFE, 0X73, 0XF6, 0X72, 0XFF, 0XF9, 0XFF, 0XFD, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XDF, 0XFF, 0XBE, 0XFF, 0XFE, 0XFF, 0XFD, 0XFF, 0XDD, 0XFF, 0XFD, 0XFF, 0XFD, 0XFF, 0XFB, 0XFF, 0X56, 0XD4, 0X89, 0XCC, 0X88, 0XFF, 0X55, 0XFF, 0XDB, 0XFF, 0XFD, 0XFF, 0XF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FF, 0XB8, 0XF5, 0XAD, 0XED, 0XCB, 0XFF, 0XF6, 0XFF, 0XFC, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFE, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XDF, 0XFF, 0XFF ]) lcd.show_image(25, 25, 24, 24, image_buf) # x, y, length, wide lcd_image_show(lcd, 70, 70, 100, 100, "ball.img") gc.collect()
from arduino import grove_mlx9064x from machine import LCD from machine import Sprite import time tft = LCD() mlx90641 = grove_mlx9064x() mlx90641.set_refresh_rate(mlx90641.rate._16HZ) spr = Sprite(tft) #create a buff to show IR data more fast MinTemp = 25 MaxTemp = 38 red = 0 green = 0 blue = 0 a = 0.0 b = 0.0 c = 0.0 d = 0.0 ShowGrid = -1 pixels = [0.0]*64 colors_table = [0]*100 XPixels = 40 YPixels = 40 HDTemp = [0.0] * XPixels * YPixels
# # Copyright (c) 2006-2019, RT-Thread Development Team # # SPDX-License-Identifier: MIT License # # Change Logs: # Date Author Notes # 2019-06-13 SummerGift first version # from machine import LCD # Import the LCD class from machine lcd = LCD() # Create a LCD object lcd.light(False) # Close the backlight lcd.light(True) # Open the backlight lcd.set_color(lcd.WHITE, lcd.BLACK) # Set background color and foreground color lcd.fill(lcd.BLACK) # Fill the entire LCD with black lcd.fill(lcd.RED) # Fill the entire LCD with red lcd.fill(lcd.GRAY) # Fill the entire LCD with gray lcd.fill(lcd.WHITE) # Fill the entire LCD with white lcd.pixel(50, 50, lcd.BLUE) # fills the pixels in the (50,50) position with blue lcd.text("hello RT-Thread", 0, 0, 16) # prints the string at 16 font size at position (0, 0) lcd.text("hello RT-Thread", 0, 16, 24) # prints the string at 24 font size at position (0, 16) lcd.text("hello RT-Thread", 0, 48, 32) # prints the string at 32 font size at position (0, 48) lcd.line(0, 50, 239, 50) # Draw a line starting at (0,50) and ending at (239,50)
def main(): lcd = LCD() lcd.light(True) lcd.set_color(lcd.WHITE, lcd.BLACK) lcd.show_bmp(180, 50, "sun.bmp")
如果用户使用的固件版本中没有checkNet库,请将checkNet.mpy文件上传到模块的usr目录, 并将 import checkNet 改为 from usr import checkNet ''' import checkNet from machine import LCD from usr import image ''' 下面两个全局变量是必须有的,用户可以根据自己的实际项目修改下面两个全局变量的值, 在执行用户代码前,会先打印这两个变量的值。 ''' PROJECT_NAME = "QuecPython_ILI9225_LCD_Example" PROJECT_VERSION = "1.0.0" checknet = checkNet.CheckNetwork(PROJECT_NAME, PROJECT_VERSION) lcd = LCD() def ili9225_display_on(args): print('ili9225_display_on') lcd.lcd_write_cmd(0x07, 1) lcd.lcd_write_data(0x1017, 2) def ili9225_display_off(args): print('ili9225_display_off') lcd.lcd_write_cmd(0x07, 1) lcd.lcd_write_data(0x1004, 2) def ili9225_display_area(args):
Value_SWITCH_DOWN = 0 Value_SWITCH_LEFT = 0 Value_SWITCH_RIGHT = 0 Value_SWITCH_PRESS = 0 # variables for reading previous button/ switch state Value_Button_A_OLD = 0 Value_Button_B_OLD = 0 Value_Button_C_OLD = 0 Value_SWITCH_UP_OLD = 0 Value_SWITCH_DOWN_OLD = 0 Value_SWITCH_LEFT_OLD = 0 Value_SWITCH_RIGHT_OLD = 0 Value_SWITCH_PRESS_OLD = 0 lcd = LCD() # TFT LCD initialization lcd.fillScreen(lcd.color.WHITE) # fill background in white # # draw lower notes with black border # lcd.drawRect(0,0,40,240,lcd.color.BLACK) # draw rectangle with black border # lcd.drawRect(40,0,40,240,lcd.color.BLACK) # lcd.drawRect(80,0,40,240,lcd.color.BLACK) # lcd.drawRect(120,0,40,240,lcd.color.BLACK) # lcd.drawRect(160,0,40,240,lcd.color.BLACK) # lcd.drawRect(200,0,40,240,lcd.color.BLACK) # lcd.drawRect(240,0,40,240,lcd.color.BLACK) # lcd.drawRect(280,0,40,240,lcd.color.BLACK) # # draw upper notes with black fill # lcd.fillRect(25,0,30,130,lcd.color.BLACK) # fill rectangle with black
from arduino import grove_dht from machine import LCD, Sprite import time dht = grove_dht(0,11) lcd = LCD() # initialize TFT LCD spr = Sprite(lcd) # initialize buffer def main(): # main function spr.createSprite(320, 240) # create buffer while True: # while loop spr.fillSprite(spr.color.WHITE) # fill background # two fill rectangles spr.fillRect(0,0,160,240,spr.color.DARKGREEN) # fill rectangle in color spr.fillRect(160,0,160,240,spr.color.BLUE) # temp and humid text draw spr.setTextSize(2) # set text size spr.setTextColor(spr.color.WHITE,spr.color.DARKGREEN) # set text color spr.drawString("Temperature", 15, 65) # draw string spr.setTextColor(spr.color.WHITE,spr.color.BLUE) spr.drawString("Humidity", 190, 65) # obtain temperature and humidity readings t = dht.temperature; h = dht.humidity # display temp readings spr.setTextSize(4) spr.setTextColor(spr.color.WHITE,spr.color.DARKGREEN) spr.drawNumber(int(t),50,110) # display number
from machine import LCD #include LCD function from machine module lcd = LCD() #initialize TFT LCD lcd.fillScreen(lcd.color.WHITE) #fill background color lcd.setRotation(3) #set screen rotation #draw for title header lcd.fillRect(0, 0, 320, 60, lcd.color.DARKGREEN) #draw rectangle with border lcd.setTextSize(3) #set text size lcd.setTextColor(lcd.color.WHITE, lcd.color.DARKGREEN) #color of text lcd.drawString("MUSIC PLAYER", 55, 15) #draw a string #draw for volume lcd.drawRoundRect(90, 75, 140, 60, 15, lcd.color.BLUE) #draw round corner rectangle with border lcd.fillTriangle(40, 105, 80, 75, 80, 135, lcd.color.RED) #draw triangle with fill color lcd.fillTriangle(280, 105, 240, 75, 240, 135, lcd.color.DARKGREEN) lcd.setTextColor(lcd.color.BLACK) lcd.drawString("VOLUME", 105, 95) #draw for play lcd.drawCircle(160, 190, 45, lcd.color.BLUE) #draw circle with fill color lcd.fillTriangle(60, 185, 100, 155, 100, 215, lcd.color.RED) lcd.fillTriangle(260, 185, 220, 155, 220, 215, lcd.color.DARKGREEN) lcd.drawString("PLAY", 130, 180)