Overview
Make a double-player penalty shootout game machine, which can detect whether the ball has passed the goal and score.
Suitable kit: mCookie302
Module Bill
Module
Other Equipment
- USB cable*1
- Sensor cable*4
- Sensor shell
- Lego or other fixation structure
Module Setup
Setup
- Assemble modules and sensors:
- Stick the red core module, battery base, and green extension module together;
- Connect the 2 color LEDs to pin 6/7 of Hub;
- Connect the line finders to pin A0/A1 and A2/A3 of Hub;
- Plug one end of USB cable into the battery base, and connect the other to computer;
Programming
Required Program Blocks
Programming Thought
If the goal 1 found the ball, and there hadn’t been a ball here in the last minute, that will be judged as score (record the score); if the goal 1 hasn’t found the ball, and there had been a ball here in the last minute, that will be judged as the ball passed (score and clear the record); goal 2 is in the same way.
Start to Program
1. Color LED prepare, and declare a variable and assign a value to it.
ColroLED prepare: connect 2 color LEDs to pin 6.
Declare a variable score1 for recording the score of player 1.
Declare a variable player1 for recording the state of goal 1.
Declare a variable score2 for recording the score of player 2.
Declare a variable player2 for recording the state of goal 2.
Display the scores of the two players on computer screen in the format of “score1: score2”.
2. Judge that the goal 1 has been passed, and score
If the state of goal 1 is 0 (no score), the internal program will be executed . If the distance value of A0 line finder is less than 600 (find score), set the state to goal 1 to 1 (score), and active color LED 1 in green.
If the state of goal 1 is 1 (score), the internal program will be executed. If the distance value of of A0 line finder is larger than 650 (the ball passed through the goal), set the state of goal 1 to 0 (ready to accept the next score), score1 increases 1, and turn the LED 1 off.
3. Judge goal 2 has been passed, and score.
If the state of goal 2 is 0 (no score), the internal program will be executed. If the distance value of A2 line finder is less than 600 (find score), set the state of goal 2 to 1 (score), and activate color LED 2 in green.
If the state of goal 2 is 1 (score), the internal program will be executed. If the distance value of A2 line finder is larger than 650 (found the ball passing the goal), set the state of goal 2 to 0 (ready to accept the next score), the variable score2 increases 1, and turn the color LED 2 off.
Test the result
After upload the program, make an object approaching the line finder and then take it away, you will see the color LED flash once in green, that is saying it is successful.
Technical Specification
Related Case
FAQ
|