# Classroom voting system: a free micro:bit lesson from Maze Education
# https://maze.education/microbit/lessons/class-vote
# MicroPython for the micro:bit Python Editor: https://python.microbit.org

# Classroom voting system: A votes yes, B votes no, and every board counts the votes it hears.
# Press A and B together to see the totals.
from microbit import *
import radio

radio.on()
radio.config(group=7)
yes = 0
no = 0

while True:
    if button_a.is_pressed() and button_b.is_pressed():
        display.scroll("Y" + str(yes) + " N" + str(no))
        button_a.was_pressed()
        button_b.was_pressed()
    elif button_a.was_pressed():
        radio.send("1")
        display.show(Image.YES)
    elif button_b.was_pressed():
        radio.send("2")
        display.show(Image.NO)
    message = radio.receive()
    if message == "1":
        yes = yes + 1
    elif message == "2":
        no = no + 1
    sleep(20)
