from machine import Pin
import network
import time
from blynkLib import Blynk
BLYNK_AUTH_TOKEN = "9FJHmvSUp4tMbYN6CI52yC6JzSDJQhDF"
led=Pin(2,Pin.OUT)
swi=Pin(21,Pin.IN, Pin.PULL_UP) # Set the switch pin as input
wifi= network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect("Wokwi-GUEST","")
while not wifi.isconnected():
pass
print("Wifi Connected Successfully")
blynk= Blynk(BLYNK_AUTH_TOKEN)
def led_control(value):
if int(value[0])==1:
led.on()
else:
led.off()
blynk.on("V0",led_control)
def switch_value(pin):
if pin.value()==1:
blynk.virtual_write(0, 255) # Turn on the LED on Blynk
else:
blynk.virtual_write(0, 0) # Turn off the LED on Blynk
swi.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=switch_value) # Add interrupt for the switch pin
while True:
blynk.run()
time.sleep(0.1)