mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add examples/Device/KEY_POLL.PY.
Signed-off-by: codercmd <codercmd@qq.com>
This commit is contained in:
parent
251c450248
commit
ff4075479d
33
examples/Device/KEY_POLL.PY
Normal file
33
examples/Device/KEY_POLL.PY
Normal file
@ -0,0 +1,33 @@
|
||||
from machine import GPIO as STD_GPIO
|
||||
|
||||
print('PikaScript LED KEY')
|
||||
|
||||
|
||||
LED1 = STD_GPIO()
|
||||
LED1.setPin('PE5')
|
||||
LED1.setMode('out')
|
||||
LED1.enable()
|
||||
|
||||
LED2 = STD_GPIO()
|
||||
LED2.setPin('PE6')
|
||||
LED2.setMode('out')
|
||||
LED2.enable()
|
||||
|
||||
KEY1 = STD_GPIO()
|
||||
KEY1.setPin('PE4')
|
||||
# setPull要在setMode前面才行,PikaStdDevice_GPIO.c函数PikaStdDevice_GPIO_setPull不赋值pull
|
||||
# PikaStdDevice_GPIO_platformSetMode中才赋值cfg->pull
|
||||
KEY1.setPull('up')
|
||||
KEY1.setMode('in')
|
||||
|
||||
KEY1.enable()
|
||||
|
||||
LED1.high()
|
||||
LED2.high()
|
||||
print(KEY1.read())
|
||||
|
||||
while True:
|
||||
if KEY1.read() == 1:
|
||||
LED1.high()
|
||||
else:
|
||||
LED1.low()
|
Loading…
x
Reference in New Issue
Block a user