MB5: Intercepting the Ball
MAKECODE
Diagram
Code
Radio Signal Range ( -42 or close / -128 or far )
Player 1: The code for Player 1 requires 1 micro:bit. On start, the playerID is set to 1, the radio group is set to 1 and the variable signalTemp is set to -128. The radio group is the same across all players to ensure everyone has a chance to catch the ball. The variable playerID (circled in dotted yellow above) is where you specify the player number, change this number for the remaining players.
The buttons A and B are used to decide if the player will start with the ball or not. If the player is starting with the ball, press A to display the ball. If they are not, press B and display nothing.
The variable signalTemp represents the stored radio signal strength coming from other micro:bits. The signal strength can be thought of as the distance between two micro:bits. This value is initally set to -128 because this is the furthest two micro:bits can be apart. This ensures that the initial value stored in signalTemp will always be replaced when searching for closer micro:bits.
When Player 1 receives a number via radio it will check if the radio signal received from that micro:bit is larger than the value stored in signalTemp. If the value is larger, the value contained in signalTemp will be replaced with the received signal strength and nextID will be set to the playerID that the signal came from.
If Player 1 receives it's own playerID, it will display the ball to show it caught it from someone else. It will also reset the signalTemp variable back to -128.
On shake, if Player 1 has the ball, the screen will be cleared, send the latest playerID stored in nextID to the other micro:bits and reset signalTemp to -128. The latest nextID(playerID) that is saved is from the player closest to Player 1. The other player will receive the nextID from Player 1, but only the player with the playerID matching the nextID sent by Player 1 will react by diplaying a ball.
While all of this is happening, the code is also always sending its own playerID to the other micro:bits.
Code available here
Player 2 - 6: The code for Player 2-6 requires 5 micro:bit. On start, the playerID is set to the specified player number, the radio group is set to 1, the ball is not displayed and the variable signalTemp is set to -128.
The only difference from Player 1 is the playerID that is used. The remaining blocks of code are the same where it uses the signal strength to deteremine the distance between the players, it will use the playerID it receives to know who is closer and will pass to the closest micro:bit.
The process to receive is the same as well where it will wait to receive its own playerID and display the ball.
Player 2 Code available here
Player 3 Code available here
Player 4 Code available here
Player 5 Code available here
Player 6 Code available here
Net 1: The code for Net 1 requires 1 micro:bit. On start, the netID is set to 7, the radio group is set to 1, a net is displayed and score is set to 0. The variable netID (circled in dotted yellow in the image above) is where you specify which net, change this number for the other net.
The Net functions the same where it is waiting for the receivedNumber to match its netID. When it does receive its own netID, it will display the ball for 2 seconds, increase score by one, display the current score for 2 seconds, and then display net again.
The Net is also constantly sending its own netID to the other players.
Code available here
Net 2: The code for Net 1 requires 1 micro:bit. On start, the netID is set to 8, the radio group is set to 1, a net is displayed and score is set to 0.
Net 2 has the same code as Net 1, the only difference is the netID that is used.
Code available here
Game
BasketBall Game | 6 players | 8 micro:bits
The 6 players will be split into 2 teams of 3, Each player will have a micro:bit and one person will start with the ball. Players can pass the ball between each other by shaking the micro:bit. When the player who has the ball shakes their micro:bit, whoever is closest will catch it.
In order to score, the player must make sure that the micro:bit displaying the net is closest to them and not another player. If the net is the closest, when the player shakes the micro:bit, they will score and the net will display the ball along with the new score.
Rules:
- Only one person can have the ball at a time
- When the game begins, make sure only one person has the ball
- The player who has the ball cannot move, all players without can move
- Players without the ball must be arm's length away from the player with the ball
- If no one has the ball, have the last person who had the ball press A to get the ball back keep going
- When a team scores, the ball will start on the others team side