pikapython/examples/Device/KEY_POLL.PY
codercmd ff4075479d
add examples/Device/KEY_POLL.PY.
Signed-off-by: codercmd <codercmd@qq.com>
2022-12-16 10:15:34 +00:00

34 lines
594 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()