pikapython/examples/Device/KEY_POLL.PY

34 lines
600 B
Python
Raw Permalink 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 PikaStdDevice 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()