Penalty Shootout

From Microduino Wiki
Jump to: navigation, search

Overview

Anywhere game ball.jpg

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

Module Number Function
mCookie-Core 1 Core board
[[mCookie-Battery|Battery box] 1 Program download and power supply
mCookie-Hub 1 Sensor adapter plate
Color LED 2 Emit light
Line Finder 2 Detect objects

Other Equipment

  • USB cable*1
  • Sensor cable*4
  • Sensor shell
  • Lego or other fixation structure
Anywhere game ball-module.jpg

Module Setup

Setup

Anywhere game ball-step.jpg
  • 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.

Mixly-ctrl-game ball.jpg

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".

Mixly-ctrl-game ball-code.jpg

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.

Mixly-ctrl-game ball-code1.jpg

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.

Mixly-ctrl-game ball-code2.jpg



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.

Anywhere game ball.jpg




Technical Specification


Related Case


FAQ