|
楼主 |
发表于 2020-7-7 15:00
|
显示全部楼层
11、实验之六:红绿灯触摸滑动自锁转换开关
- #MicroPython动手做(38)——控制触摸屏
- #实验之六:红绿灯触摸滑动自锁转换开关
- import touchscreen as ts
- import time
- import mixno
- import lcd
- import image
- from machine import I2C
- lcd.init(freq=15000000,color=0)
- i2c = I2C(I2C.I2C0, freq=400000, scl=30, sda=31)
- ts.init(i2c)
- image = image.Image()
- LED_R=mixno.pin(7,mixno.GPIO.OUT)
- LED_G=mixno.pin(6,mixno.GPIO.OUT)
- x = 0
- image = image.draw_rectangle([50,80,60,80],7936,1,1)
- while True:
- if 50 < ts.read()[1] < 110 and 80 < ts.read()[2] < 160:
- while 50 < ts.read()[1] < 110 and 80 < ts.read()[2] < 160:
- time.sleep_ms(12)
- x = not x
- if x == 0:
- LED_R.value(0)
- else:
- LED_R.value(1)
- if x == 1:
- LED_G.value(0)
- else:
- LED_G.value(1)
- lcd.display(image)
复制代码
|
|