

We also use ||basic:show icon|| to display the current game state. When A is pressed, the game goes into GREENLIGHT mode. Use the ||input:on button pressed|| block to run code when button A and B are pressed. let REDLIGHT = 0Ī ||basic:forever|| loop will broadcast the game state so that players continuously receive it. We will set the same group in the player’s code too. The radio group for all game players is set to 1. When they press B, the state goes into “red light” mode. First to press the finish button wins Game 2: 'Sneaky Steps' - Move slowly If the motion detector catches you moving too fast go back to the starting line. If the motion sensor catches you moving on Red go back to the starting line. When the stoplight player presses A, the game goes into “green light” mode. Game 1: 'Red Light, Green Light' - Run on Green, Freeze on Red. A variable named state will store the current game state. We define two states, or game conditions, called GREENLIGHT and REDLIGHT. Don’t use this code for the other players! States Let’s start with the code running on the stoplight’s micro:bit.


Open to launch 2 side-by-side micro:bit editors. You can code and test two radio programs using the multi-editor feature. It’s helpful to know how a second micro:bit will respond This project uses radio to communicate status to other micro:bits. In this remake of the game, we will use a micro:bit, its radio, and the accelerometer to enforce these rules! The game continues until only the the stoplight player remains. If one of the other players happens to touch the stop light player before they can turn around when saying “Red Light!”, then the current stoplight player moves to the beginning of the course and the other player becomes the stoplight. The stoplight player repeats the red light, green light cycle. If the stop light player sees anyone still moving, they call them out and they are finished playing until a new game is started. The stoplight player can at any time say “Red light!” and then turn around to face the other players. The other players move toward the stoplight player, from a distance set at the beginning of the game, and try to touch them. The player chosen as the current the stoplight says “Green Light!” and turns away from the other players. This is the classic “Red Light, Green Light” game where one person is a virtual stoplight and gives commands to the other players to either stop or go.
