|
楼主 |
发表于 2020-7-7 12:09
|
显示全部楼层
9、实验之四:红蓝触摸块控制红蓝色LED灯
红蓝二个色块按钮,点动打开相应颜色的LED灯
- #MicroPython动手做(38)——控制触摸屏
- #实验之四:红蓝触摸块控制红蓝色LED灯
- import touchscreen as ts
- import mixno
- import lcd
- import image
- from machine import I2C
- i2c = I2C(I2C.I2C0, freq=400000, scl=30, sda=31)
- lcd.init(freq=15000000,color=0)
- ts.init(i2c)
- LED_R=mixno.pin(7,mixno.GPIO.OUT)
- LED_B=mixno.pin(8,mixno.GPIO.OUT)
- image = image.Image()
- image = image.draw_rectangle([50,80,60,80],248,1,1)
- image = image.draw_rectangle([190,80,60,80],7936,1,1)
- while True:
- if 50 < ts.read()[1] < 110 and 80 < ts.read()[2] < 160:
- LED_R.value(0)
- else:
- LED_R.value(1)
- if 190 < ts.read()[1] < 250 and 80 < ts.read()[2] < 160:
- LED_B.value(0)
- else:
- LED_B.value(1)
- lcd.display(image)
复制代码
|
|