Overview
Align the numbers 1-6 on the second line with the random number on the first line (if the random number is 2, align the 2 on the second line to it) through turning the potentiometer, after the numbers are aligned, the buzzer will buzz and Score+1.
Analysis
In Bingo Game Machine 01, the range of b is set to 0-90. List the correspondence relation formula according to the values of a and b on the picture:
a = (b+18) / 18, simplified into a = b / 18+1
The requirement of the alignment as so is very high, which can’t stand for a little deviation. It is too difficult. So alignment just in a range is OK.
In Bingo Game Machine 01, the range of b is set to 0-90. We can judge the number to be aligned through a equation: aligned number=(b+27)/18
Module List
Module
Other Equipment
- USB cable*1
- Sensor cable*2
- Sensor shell
- Building blocks or other fixation structures
Module Setup
Setup
- Assemble modules and sensors together:
- Stick the red core module, battery base, OLED and green Hub together;
- Connect the Buzzer to pin 8/9 of Hub;
- Connect the potentiometer to pin A0 of Hub;
- Plug one end of the USB cable into the battery base, and connect the other to the computer;
Program
Programming Thought
Declare variables for storing data, write function start for producing random numbers, producing a random number when the condition is matched; write function display for display on OLED, displaying the game interface on OLED; write function BINGO for judging the alignment, after alignment, score+1 and the buzzer buzzes. Finally, execute all functions.
Required Program Blocks
Start to Program
1. Declare variables for storing data
Variable bingo if for storing the alignment state of numbers
2. Write function start for producing random numbers, producing one each time
If variable bingo is 1 (the numbers have been aligned, so it can reproduce a new random number), produce a new random number, set variable bingo to 0.
3. Write function display for display on OLED
Function display isn’t changed.
4. Write function BINGO, when the numbers are aligned, the buzzer buzzes and score one
If the result of (b+27) /18 is a (the numbers have been aligned), set bingo to 1 (inform function start: numbers are aligned), score adds 1 (score) and buzzer buzzes once.
5. Execute functions
Execute “start”, “display” and “BINGO” three functions
Test the result
After upload, display a random number on the first line of the OLED, display “1 2 3 4 5 6” on the second line and display SCORE: 0 on the third line. Tuning the potentiometer, the “1 2 3 4 5 6” can be moved. When the random number is aligned to the corresponding number, SCORE on the third line adds 1, and buzzer buzzes.
Q: If two random numbers produced in two successive times are same, you can get points successively, that is unfair!
A: Confirm the random number produced this time is different from the last one. If it is same with the last once, reproduce one until it is different from the last one
A new variable is needed for storing the new random number (a_random), when the current random number is same to the new one, reproduce one. Otherwise, save the value of a_random into a. Keep function BINGO and display unchanged.
Programming
Technical Specification
Relative Cases
FAQ
|