In this challenge you will create a voting system using the BBC micro:bit. You can complete the code online on the BBC micro:bit website.
The idea is to use the BBC micro:bit in the classroom to conduct a survey by asking a yes/no question such as:
- Should our school change our school uniform?
- Should we have more computer science lessons on our timetable?
- Should we have more healthy eating options on our school menu?
Then you will pass the micro:bit around so that each pupil can vote using the A and B buttons of the microbit:
- A: Vote Yes
- B: Vote No
Using two variables called voteA and voteB the BBC micro:bit will keep track how many times the A button is pressed and how many times the B button is pressed.
After each vote the BBC micro:bit will display a tick for two seconds to confirm the vote.
To finish the vote the user will press both A and B buttons at the same time. In this case the BBC micro:bit will display how many A votes have been recorded (variable voteA), how many B votes have been recorded (variable voteB) and then use an If Statement to decide if option A (Yes) Or B (No) wins. To do so it will use comparison operators such as > or <. (if voteA > voteB then A wins)
Building the voting system step by step:
Complete and Test your Voting System
Complete the system using the code provided above.
Test the game using the online emulator. Then when you are confident if fully works, download your code to the BBC micro:bit and conduct your first survey with your classmates. Make sure you ask for a question with only two possible answers (e.g. Yes/No question).