指间ESP按键操作
指间ESP按键操作
import machine, display
from machine import Pin
btA = Pin(0, Pin.IN)
btB = Pin(35, Pin.IN)
bkcolor = 0x333333
tft = display.TFT()
tft.init(tft.ST7789)
tft.clear()
tft.rect(0, 0, 240, 240, bkcolor, bkcolor)
while True:
if btA.value():
tft.roundrect(10, 110, 50, 50, 10, bkcolor, 0x00F0F0)
else:
tft.roundrect(10, 110, 50, 50, 10, bkcolor, 0xF0F000)
if btB.value():
tft.roundrect(180, 110, 50, 50, 10, bkcolor, 0x00F0F0)
else:
tft.roundrect(180, 110, 50, 50, 10, bkcolor, 0xF0F000)
import machine, display
from machine import Pin
之后声明按键A与B btA = Pin(0, Pin.IN)
btB = Pin(35, Pin.IN)
初始化TFT并使用背景色"bkcolor"填充屏幕 bkcolor = 0x333333
tft = display.TFT()
tft.init(tft.ST7789)
tft.clear()
tft.rect(0, 0, 240, 240, bkcolor, bkcolor)
主程序中扫描按键,按下则绘制黄色圆角矩形,否则绘制青色圆角矩形 while True:
if btA.value():
tft.roundrect(10, 110, 50, 50, 10, bkcolor, 0x00F0F0)
else:
tft.roundrect(10, 110, 50, 50, 10, bkcolor, 0xF0F000)
if btB.value():
tft.roundrect(180, 110, 50, 50, 10, bkcolor, 0x00F0F0)
else:
tft.roundrect(180, 110, 50, 50, 10, bkcolor, 0xF0F000)
|