Truth or Dare
Learn about random numbers, inputs, and outputs in this fun activity!
This project teaches you how to use button inputs and LED outputs to create a fun 'truth or dare' game using the micro:bit!
The students can:
- Display own patterns on the LEDs
- Create a randomly generated variable
- Use an IF...THEN...ELSE
- Run two programming blocks at once
- Display own patterns on the LEDs
Standards Alignment (United Kingdom: CAS)
- Designs simple algorithms using loops, and selection i.e. if statements. (AL)
- Declares and assigns variables. (AB)
- Uses a variable and relational operators within a loop to govern termination. (AL) (GE)
- Uses logical reasoning to predict outcomes. (AL)
- Detects and corrects errors i.e. debugging, in algorithms. (AL)
- Creates programs that implement algorithms to achieve given goals. (AL)
- Understands that programming bridges the gap between algorithmic solutions and computers.(AB)
- Uses nested selection statements. (AL)
This program will show an arrow to select the player following a spin of the micro:bit. The user then presses the A button to see a randomly generated statement choosing from either Truth or Dare.
The first stage is to create the arrow. From the basic option in the block menu, select the “show leds” block.
Drag the “Show leds” block onto the workspace and draw the pattern by clicking on the boxes that you want to light up. A red led indicates on.
To ensure the LEDS are always shown, the LEDs are to be placed within a forever loop. The loop can be found from the basic option from the block menu. Drag the block and place around the LEDs.
The next part of the program displays a random statement once the user has pressed a button. Select the Input option from the block menu and find the “On button press” block and drag onto the workspace.
The result of the random function needs to be stored within a variable. From the block menu select the “Variable” and click “Make a Variable”.
A popup dialogue box will then ask you to name your variable. In this example name it “Random”.
Using the “set item” block, drag it onto the workspace and connect to the button “A” input block.
Now the variable “Random” has been created this can be found on the “Set item” drop down menu by pressing the down arrow and selecting “Random”.
Now that the variable is set to “0” when the A button is pressed, we now need to assign a random number to it. From the block menu select the “Math” option and select “pick random 0 to 4”
Drag the “pick random” block onto the workspace and join to the “set random” block. A random number between 0 and 1 will give us the 2 options needed.
Now we include a selection process using the IF statements found within the “logic” option within the block menu.
Drag the “IF” block into the workspace and connect it to follow the “random” block.
Next there we need to create a logical statement for the IF statement to be based upon to allow for selection. Again from the “logic” option on the block menu, add an “equals” block.
To ensure the micro:bit bases the IF statement on the random number, the value stored in the variable “Random” needs to be checked. The “Random” variable can be found from the variable option in the block menu.
The “Random” variable block is placed in the “equals” block to test the IF statement logic. If the “Random” variable contains a “0” the first option is selected otherwise the second option is chosen.
To get the “truth” or “Dare statements displayed on the screen the “show string” block is required from the basic option on the block menu.
The program is completed and both elements will work together at the same time, displaying the led arrow pattern, when the button hasn’t been pressed.
Save the project and download to the micro:bit.
Try to add the following functionality:
- Add the number of player in the game and display who is playing.
- Add different directions of the arrow.
- Add an animation of the arrow spinning.
- Add a score based system whether completed the truth or dare.
The 'Magic 8' activity builds on this project to create a question-based game.