from machine import pin
import time
button = Pin(12,Pin.IN,Pin.PULL_DOWN)
led = Pin(1,Pin.OUT)
while true:
if button.value():
led.toggle()
time.sleep(0.5)
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
while True:
GPIO.output(18, GPIO.input(17) == GPIO.LOW) # LED ON when button pressed
sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()