add micropython demo on bearpi board

This commit is contained in:
KY-zhang-X
2022-09-29 12:15:02 +08:00
parent afeaebd1b9
commit 3e4ceb8afe
49 changed files with 14399 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
import umachine as machine
import utime as time
running = True
def key1_irq_callback(pin):
if pin.value() == 0:
print('Key1 is pressed')
else:
print('Key1 is released')
def key2_irq_callback(pin):
global running
running = False
if __name__ == '__main__':
led = machine.Pin("LED", mode=machine.Pin.OUT)
key1 = machine.Pin("KEY1", mode=machine.Pin.IN_PULLUP)
key1.irq(trigger=machine.Pin.IRQ_RISING|machine.Pin.IRQ_FALLING, handler=key1_irq_callback)
key2 = machine.Pin("KEY2", mode=machine.Pin.IN_PULLUP)
key2.irq(trigger=machine.Pin.IRQ_FALLING, handler=key2_irq_callback)
while running:
led.on()
time.sleep(0.5)
led.off()
time.sleep(0.5)