Overview
Optimize the program of position detection, preventing scoring through turning the potentiometer casually.
Module List
Module
Other Equipment
- USB cable*1
- Sensor cable*3
- 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;
- Connect the ColorLED to pin 6/7 of Hub;
- Plug one end of USB cable into the battery base, and connect the other to computer.
Programming
Programming Thought
Other programming thought is same with that of the last course, and a score condition judgement is required, when score is 15, the green LED lights 1s and then goes off, reset score.
Required Program Blocks
Start to Program
1. Declare variables for storing data
2. Victory judgement
Content of function win: if score is 15 (score 15 points), the green LED will light 1s, reset variable score.
3. Function start isn’t changed.
4. Function display isn’t changed.
5. Function BINGO isn’t changed.
6. Function time_out isn’t changed.
Test the result
After upload, display the random number (reproduce it if it hasn’t been aligned in 3s) on the first line, display “1 2 3 4 5 6” on the second line, and display SCORE: 0 on the third line. Move “1 2 3 4 5 6” with the potentiometer. Only after a while from the numbers were aligned can score, the score displayed on the third line will change. When the score is larger than 15, the green LED will light 1s, and then the game will restart.
Q: When the Joystick being pressed is detected, the game begins, and the duration time will be displayed at the end of the game.
A: Today we will learn a new program block, which can be executed once at the beginning of the program and be never executed again after that
Start the setup function, wait for the Joystick to be pressed, then the game starts and timeout begins. When the score arrives 15, timeout ends, wait for the Joystick to be pressed to restart the game.
1. Variable time is for storing the completion time
2. Write the function setup
The function setup waits for the Joystick to be pressed (switch), timer2 begins, for storing the completion time.
3. Change function win
If score gets 15, save the value of timer2 in variable time, divide variable time with 1000 (because the unit of the initial value of time is ms). Display the value of time on OLED. Green LED lights 1s. Wait for the Joystick to be pressed (switch).
4. Function start isn’t changed.
5. Function BINGO isn’t changed.
6. Function time_out isn’t changed.
Technical Specification
Relative Cases
FAQ
|