Close menu

Resources


PIPER COMPUTER

Everything you need to teach STEAM effectivly using the Piper Computer Kit.

Educator Guides StoryMode Project Guides PiperCode Project Guides
PIPER MAKE

Teach fundamental STEM skills while providing a bridge to career connected learning.

Educator Guides
Best Practices Standards Glossary FAQ Educator Forum

EDUCATOR PORTAL

Close menu

ALL GUIDES


StoryMode

  1. Mars
  2. Cheeseteroid
  3. Treasure Hunt
  4. Chain Reaction
  5. Power Plant
  6. Rainbow Bridge
  7. Funky Fungi
  8. Breadboard Bluffs
  9. Return to the Cheeseteroid

  1. Pip Hop
  2. Bot Builder

  1. Ring Race
  2. Snake Trap
  3. Dark Maze
  4. Explosive Escape
  5. Chest Quest

PiperCode

  1. Blink
  2. Stop Light
  3. Light Show
  4. Tally
  5. Siren
  6. Circuit Design
  7. Debug
  8. Frog Frenzy

  1. Color Coded
  2. Ther-Mood-Stat
  3. Security Zone

  1. Randomizer
  2. El Pangolin (Simon)
  3. Beat the Buzzer
  4. 5-Button Synthesizer

PIPER COMPUTER

PROJECT GUIDES


YOU ARE HERE

PiperCode

Project Extra

PiperCode Project Extra

Randomizer


Intermediate

45 Mins

Grades 3 - 8

Look for the graphic above
to launch the project
INTRODUCTION

Snake eyes! Learn how to simulate a dice roll by making a random number generator.

This is a game of chance which simulates rolling of dice by using a random number generator. The code checks to see what number was ‘rolled’ and turns on a corresponding LED. The step-by-step instructions in the tutorial guide students through the process of building the circuit and writing the code.

PROJECT MATERIALS

Piper Computer Kit
4 LEDs (red, blue, yellow, green)
10 Wires (5 yellow, 5 blue)
Push Button
Breadboard

PROJECT RESOURCES

Concepts

In this project, students will program a probability tool that will randomly light an LED with the press of a button. Probability is a key skill to build games of chance! A random number generator block is used to provide the probability. Students set the low and high values of the random number to 1 and 4, and thus they always receive a value between those numbers. Other key skills in this project are variables, conditionals, timer, states and debugging.

Troubleshooting Tips

  • Troubleshooting certainly starts to get more complex at this level. Have the students focus on each individual code block and understand the logic behind it. The random number is created by the Raspberry Pi and it is a number between 1 and 4. This is stored in the variable named ‘i’ in the block (set i to random number from one to four).
  • Four if blocks are used to check the value of the variable ‘i’. One of the blocks will equate to true. Whichever one it is, the Turn Pin On code in that if block is run.
  • Make sure that students are testing their work during step #11.
  • There are several steps where students are instructed to delete blocks that are not used as part of the gradual debugging of code. Make sure they deleted the correct ones.
  • Students build the primary code and then insert it into the block that checks to see if the button is pressed (if pin 39 is ON). Then they insert all of that code into a repeat forever block. Mistakes can happen with these moves of code blocks.

Our customer support specialists are on hand to ensure your implementation of Piper runs seamlessly.
View Support Docs or Contact Support
PROJECT STEPS

Step 1 Get your stuff!

Take out the inventory you see in the picture below.

Step 2 Generate a random number

We will generate a random number and assign it to the variable i.

Step 3 Print it

We will print the random number using a Print block. Add a Wait block so we have time to see it.

Step 4 Use the console

Now turn on the console and run your code. What you see is the random number!

Step 5 Hook up the LED's

Now wire your LEDs.

GPIO Setup Red LED Pins: 39, 37
Yellow LED Pins: 35, 33
Green LED Pins: 31, 29
Blue LED Pins: 23, 21

Step 6 Test the LED's

Turn on all your LEDs to test them with this code.

Step 7 Delete the other lights

For now delete the other pin statements, we'll use the red LED first.

Step 8 Red LED

Now using an If statement, we will turn on the red LED when the random number is 1.

Step 9 Ready to proceed

We can delete the Print and Wait statements since we're done testing for now.

Step 10 Assign IF blocks to random numbers

Now, right-click and duplicate the If statement 3 times, and attach the If statements to the block above.

Step 11 All the LED's

Great. Now make the new pins 33, 29, and 23. Make the new If blocks check numbers 2, 3, and 4. Test it!

Step 12 Add a repeat forever

Now add a Repeat Forever block. Run this code. What happens?

Step 13 Turn off the LED's

We have to turn off the LEDs. Add a Wait block and 4 Pin Off blocks. Test it!

Step 14 Wire a button

Add a button to your randomizer.

GPIO Setup Push Button: 5,3

Step 15 Code the button

To make the button work, wrap the inner code in an If statement that checks pin 3. Test it!

Step 16 Play the game!

Press Start and enjoy it!

Completed!