案例使用的是3.5寸(JC035)集成串口屏,通过TTL串口进行连接.以下是JC350串口屏粗略介绍,详细信息自行翻阅资料.
JC035串口屏有自带的辅助测试软件,可以用来发送指令,处理图片.
案例说明
使用开发工具将需要的图片素材下载到集成串口屏中.
先将需要的素材像素处理成合适大小,案例使用的屏幕大小为480x320,图片像素最大为479*319.
将集成串口屏连接开发板,烧写程序
mian.py
# coding=utf-8
# This is a sample Python script.
import utime
from driver import UART
from driver import GPIO
#按键实例化
key1=GPIO(10,10)
key2=GPIO(10,10)
key1.open("key1")
key2.open("key2")
#饮料属性设置
beverages = [2402754,2482754,2562754,2642754]
QR_code = ['雪碧','可乐','冰红茶','绿茶']
price = ['30元','40元','35元','60元']
#左键设置
i = len(beverages)
flag1 = 0
def key1_callback(args):
global flag1,n,payment,flag2
flag1 +=1
n = flag1%i
#一次性发送指令 清屏,屏幕方向,二维码,价格按钮,商品图片
UART_send("CLR(0);DIR(1);QRCODE(40,60,%s,200,2);BTN(90,230,64,32,%s,0,0,4,0);FSIMG(%d,240,60,200,200,0);\r\n"%(QR_code[n],price[n],beverages[n]))
payment = True
flag2 = False
utime.sleep_ms(100)
key1.disableIrq()
key1.clearIrq()
#右键设置
flag2 = False
payment = True
def key2_callback(args):
global n,flag2,payment
if payment:
if flag2:
UART_send("CLR(0);DIR(1);BTN(160,100,64,32,'支付成功',0,0,3,0);\r\n")
flag2 = False
utime.sleep(1)
UART_send("DIR(1);FSIMG(2097152,0,0,479,319,0);BTN(100,30,64,32,'请按左键选择商品',0,0,2,15);\r\n")#开机logo
# UART_send("CLR(15);DIR(1);BTN(100,100,64,32,'请按左键选择商品',0,0,3,15);\r\n")
payment = False
else:
UART_send("CLR(0);DIR(1);BTN(60,100,64,32,'请确认是否支付%s?',0,0,4,0);BTN(400,270,64,32,'是',0,0,1,0);BTN(40,270,64,32,'否',0,0,2,0);\r\n"%price[n])
flag2 = True
utime.sleep(1)
key2.disableIrq()
key2.clearIrq()
def UART_send(data):
writeBuf0=bytearray(data)
uart0.write(writeBuf0)
if __name__ == '__main__':
uart0=UART()
uart0.open("serial1")
utime.sleep(1)
writeBuf0=bytearray("DIR(1);CLR(0);\r\n")
uart0.write(writeBuf0)
utime.sleep_ms(10)
#开机选择商品界面
UART_send("DIR(1);FSIMG(2097152,0,0,479,319,0);BTN(100,30,64,32,'请按左键选择商品',0,0,2,15);\r\n")
utime.sleep_ms(1000)
key1.enableIrq(key1_callback)
key2.enableIrq(key2_callback)
board.json
{
"name": "haas506",
"version": "2.0.0",
"io": {
"key1": {
"type": "GPIO",
"port": 20,
"dir": "irq",
"pull": "pullup",
"intMode":"rising"
},
"key2": {
"type": "GPIO",
"port": 18,
"dir": "irq",
"pull": "pullup",
"intMode":"rising"
},
"serial1":{
"type":"UART",
"port":0,
"dataWidth":8,
"baudRate":115200,
"stopBits":1,
"flowControl":"disable",
"parity":"none"
},
"serial2":{
"type":"UART",
"port":1,
"dataWidth":8,
"baudRate":115200,
"stopBits":1,
"flowControl":"disable",
"parity":"none"
},
"serial3":{
"type":"UART",
"port":2,
"dataWidth":8,
"baudRate":115200,
"stopBits":1,
"flowControl":"disable",
"parity":"none"
}
},
"debugLevel": "ERROR",
"repl":"enable",
"replPort":2
}