Overview
Implement the basic display function of the game machine: display a random number on the first line of OLED; display numbers 1-6 on the second line, which can be controlled to roll with a potentiometer; display the score on the third line.
Rule
Module List
Module
Other Equipment
- USB cable*1
- Sensor cable*1
- 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 Potentiometer to pin A0 of Hub;
- Plug one end of the USB cable into the battery base, and connect the other to the computer.
Programming
Required Program Blocks
Programming Thought
Declare variables to save data, and write function start to produce random numbers, producing one number each time; write function display to display on OLED, displaying the game interface on OLED. At last, run all functions.
Start to Program
1. Declare variables for storing random numbers and scores
Variable a is for storing random numbers and variable score is for storing scores.
2. Write function start for producing random numbers
Produce a random number between 1-6 and save it in a.
3. Write function display to display on OLED
Random number a is displayed on the first line of OLED
“1 2 3 4 5 6” is displayed on the second line and the x coordinate is the value of the potentiometer.
SCORE:score (variable for scores) is displayed on the third line
4. Execute fucntions
Execute “start” and “display” two functions. Pay attention to that functions should be put below the declarations.
Test the result
After upload, the random number displayed on the first line of OLED is changing, “1 2 3 4 5 6” is displayed on the second line, and SCORE:0 is displayed on the third line. “1 2 3 4 5 6” on the potentiometer moves OLED quickly.
Q: The width of “1 2 3 4 5 6” is only 90 pixels, the value of the potentiometer is 0-1023, so it is difficult to control to align numbers, how to solve that?
A: You can restrain the range of the movement with map program block.
- Map the value of the potentiometer from 1023-0 to 0-90 (it is 90 on left most, and it is 0 on right most), store the result in b.
- Set the x coordinate of numbers on the second line to 60-b (because the x coordinate of the random number on the first is 60, when the potentiometer is turned to left most, number 6 on the second number is aligned to the random number; when the potentiometer is turned to right most, the x coordinate of the numbers on the second line is also 60, aligned to number 1).
Variable b is for storing the random number.
Function start is not changed.
Change the content of function display.
Map the value of the rotation potentiometer from 1023-0 to 0-90 (it is 0 on left most, and it is 90 on right most), store the result in b.
Set the x coordinate of numbers on the second line to 60-b (because the x coordinate of the random number on the first line is 60, when b is 0, the x coordinate of numbers on the second line is also 60, it is just aligned to 1).
Technical Specification
Relative Cases
Bingo Game Machine 02
Bingo Game Machine 03
Bingo Game Machine 04
Bingo Game Machine 05
FAQ
|