Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
Created November 8, 2022 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neosarchizo/8fbb13ed714f058169c110e083713a24 to your computer and use it in GitHub Desktop.
Save neosarchizo/8fbb13ed714f058169c110e083713a24 to your computer and use it in GitHub Desktop.
MicroPython - LED & 스위치 제어하기
from machine import Pin
led = Pin(2, Pin.OUT)
key = Pin(0, Pin.IN, Pin.PULL_UP)
while True:
state = not key.value()
led.value(state)
from machine import Pin
from time import sleep_ms
led = Pin(2, Pin.OUT)
key = Pin(0, Pin.IN, Pin.PULL_UP)
state = 0
def on_falling(_):
global state
sleep_ms(10)
if key.value() == 0:
state = not state
led.value(state)
key.irq(on_falling, Pin.IRQ_FALLING)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment