3.1.4
Red Light Green Light
Red Light Green Light
In this session, you'll create and program a video game using a game controller that interacts with a traffic signal. But wait...how does a game controller work? And how can the same electromagnetic waves that make a game controller work be used to make driving safe?
What to expect
Imagine navigating a busy city like Chicago—your job is to drive a car in the game while avoiding traffic jams, all controlled by a stop:bit traffic light system. In this activity, you will explore:
Hands-on Coding: You’ll program a stoplight system using MakeCode and integrate it with a radio-controlled arcade game.
Interactive Gameplay: Your game controller will respond to the stoplight signals, determining when you can go or when you must stop.
Creativity & Problem-Solving: Experiment with timing, signals, and game mechanics to create a fun, interactive experience.
Connections
In the past activities, we learned how to program the traffic light to replicate the busy streets in Chicago. This activity will teach us how to program our stop:bit to interact with a game controller through radio signals. By the end of the session, you’ll have a fully functional game, and you can challenge yourself or your friends to see who gets the highest score!
Materials
Stop:bit
Arcade controller
Instructions
Figure 1. Creating a Project to Program the Stop:bit
First, we will open Makecode and name our game, as shown in Figure 1.
Figure 2. Selecting Radio Set Group
2. Next, we are going to set a radio signal. For this example, we will select “radio set group 1” as shown in Figure 2; however, you can set it to whatever you want. Make sure your radio signal is not the same as anyone else's number, or this will not work.
Figure 3. Selecting Extensions to Add Stop:bit
3. Next, click on the extensions.
Figure 4. Kitronik-stopbit
4. Next, add an extension called “kitronik-stopbit.” as shown in Figure 4.
Figure 5. Forever Loop for Traffic Light
5. After this, we are going to make a forever loop as shown in Figure 5. First, we will add a basic code to have the green light on.
Figure 6. Adding a Random Time Limit
6. Next, we will add a random time limit for green, as shown in Figure 6. This example picked half a second to ten seconds, but you can adjust it however you like. This example also added a 1-second-long yellow light and a 2- second long red light.
Figure 7. Adding Radio Send Numbers
7. After that, we will add our radio send number: “1” for go and “0” for stop, as shown in Figure 7. This will let the code in our video game know when the light is on green or red. You can download the code for the traffic light here. https://makecode.microbit. org/_THqcodLAT3cc
Figure 8. Codes for the Game, “Driving through the Busy Road”
8. Now, it’s time to download the code to your micro:bit that is attached to the stop:bit.
Once the stop:bit is set up, we will move on to Arcade Controller. You can create the game on your own using the example codes as shown in Figure 8. You can also download the game to play. You can edit the code to download the game using the link below. https://arcade.makecode.com/S18759-74892-74401-24939
Figure 9. Radio Set Group on Arcade Controller
9. Make sure that the radio set group is the same as the set group in the code for the stop:bit as shown in Figure 9.
Figure 10. Kitronik Arcade for Micro:bit
10. Once all of the coding is done, you can download the code from the video game and put it onto the arcade game controller. When you download this code, make sure to select the Arcade for micro:bit, as shown in Figure 10.
Figure 11. Time to Play!
11. Now, you can play the game using the game controller. Make sure your controller is connected to the stop:bit by checking the “GO” and “STOP” signals. This game is designed to test your driving skills. You will drive your red car on a day with many cars on the road. Your job is not to crash into the cars on the road. Once you turn on both your stop:bit and the arcade controller, you are ready to play the game!
Think about it
Congratulations you finished this activity! In this activity, we programmed a traffic light and integrated it into a video game. It’s the first time you coded your game controller. You will use the game controller for the upcoming activities too!
What else can you do with radio signals?
What is your high score on the game?
Would you like to try to code your own video game? If so, what kind of game do you want to create?
Next Activity
In the following activities, we will use our knowledge of radio signals and coding to control a tiny car to move.