# Code 1:
# MicroPython LED Blink Code for Wokwi
from machine import Pin
import time
# Set GPIO 13 as output
led = Pin(13, Pin.OUT)
# Set GPIO 2 as input (use sw.value() to read its state)
sw = Pin(2, Pin.IN)
while True:
if sw.value() == 1: # Check input pin correctly
led.value(1) # Turn LED ON
else:
led.value(0) # Turn LED OFF
# Code 2:
"""
from machine import Pin
import time
# Set GPIO 13 as output
led = Pin(13, Pin.OUT)
while True:
led.value(1) # Turn LED ON
time.sleep(1)
led.value(0) # Turn LED OFF
time.sleep(1)
"""
# Code 3:
"""
import RPi.GPIO as GPIO # Import the Raspberry Pi GPIO library
from time import sleep # Import sleep function to create delays
GPIO.setmode(GPIO.BOARD) # Set pin numbering mode to physical pin numbers
GPIO.setup(13, GPIO.OUT) # Configure pin 13 as an output pin
while True: # Create an infinite loop
GPIO.output(13, True) # Set pin 13 to HIGH (turn ON the LED)
sleep(1) # Wait for 1 second
GPIO.output(13, False) # Set pin 13 to LOW (turn OFF the LED)
sleep(1) # Wait for 1 second
"""
# Code 4:
"""
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(2,GPIO.IN)
while True:
if GPIO.input(2) == GPIO.HIGH:
GPIO.output(13, True)
else:
GPIO.output(13, False)
"""Loading
pi-pico-w
pi-pico-w