1.copy the script in main.py
2.restart (e.g. CTRL+D in putty)
3.Script end when you press a Button (USR), e.g. control of putty
Code: Select all
lcd = pyb.LCD('X')
i2c = pyb.I2C(1, pyb.I2C.MASTER)
i2c.mem_write(4, 90, 0x5e)
switch = pyb.Switch()
lcd.light(1)
def tobin(n):
re="b"
if n & 8:
re+="1"
else:
re+="0"
if n & 4:
re+="1"
else:
re+="0"
if n & 2:
re+="1"
else:
re+="0"
if n & 1:
re+="1"
else:
re+="0"
return str(re)
while not switch():
touch = i2c.mem_read(1, 90, 0)[0]
lcd.fill(0)
lcd.text("touchdemo "+tobin(touch), 0, 0, 1)
if touch & 8:
lcd.text("A", 0, 10, 1)
if touch & 4:
lcd.text("B", 16, 10, 1)
if touch & 2:
lcd.text("X", 0, 20, 1)
if touch & 1:
lcd.text("Y", 16, 20, 1)
lcd.show()
pyb.delay(25)
lcd.light(0)
lcd.write('by\n\n\n ')