from machine import Pin
import time
buzzer = Pin(15, Pin.OUT)
button1 = Pin(0, Pin.IN, Pin.PULL_DOWN)
button2 = Pin(1, Pin.IN, Pin.PULL_DOWN)
button3 = Pin(2, Pin.IN, Pin.PULL_DOWN)
button4 = Pin(3, Pin.IN, Pin.PULL_DOWN)
led = Pin(5, Pin.OUT)
INC = 0
BJP = 0
OTH = 0
def led_operation():
led.value(1)
time.sleep(0.3)
led.value(0)
def buzzer_operation():
buzzer.value(1)
time.sleep(0.3)
buzzer.value(0)
while True:
if button1.value() == 1:
INC += 1
led_operation()
buzzer_operation()
time.sleep(0.3) # debounce
elif button2.value() == 1:
BJP += 1
led_operation()
buzzer_operation()
time.sleep(0.3)
elif button3.value() == 1:
OTH += 1
led_operation()
buzzer_operation()
time.sleep(0.3)
elif button4.value() == 1:
print("----- Voting Result Window -----")
print("INC Votes:", INC)
print("BJP Votes:", BJP)
print("OTH Votes:", OTH)
if INC > BJP and INC > OTH:
print("INC Wins")
elif BJP > INC and BJP > OTH:
print("BJP Wins")
elif OTH > INC and OTH > BJP:
print("OTH Wins")
else:
print("Tie / Results Awaited")
break