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 Sensor Explorer

Project 1 of 3

PiperCode Project

Color Coded


Intermediate

45 Mins

Grades 3 - 8

Look for the graphic above
to launch the project
INTRODUCTION

Code secret messages and make sure to hide your ~true colors~

Students will learn how to use a color sensor to create a secret message. By the end of the lesson, students will understand how colors can be represented by numbers (RGB values) and use these values in code to reveal a hidden message. A real world example is if you want to buy a specific color blue you saw in a picture to paint your room. A color sensor would help by scanning the picture and giving you the exact RGB values!

PROJECT MATERIALS

Piper Computer Kit
Color Sensor
Breadboard
4 Wires
4-Pin Jumper Cable
Different colored markers and white paper

Newer Sensor Explorer Kits are now shipping with a 4-pin cable that has a white wire instead of a green wire. When you see the green wire in a wiring diagram, just connect the white wire instead.


PROJECT RESOURCES

Concepts

Students use sequences and simple loops to make a program spell out letters in the display when the RGB values are entered into the code. Color Coded is a great step for learning how to create programs that include sequences, events, loops, and conditionals.

Troubleshooting Tips

  • Be sure to hold the color sensor as steadily as possible and wait for the RGB values to stabilize.
  • It is better to enter in the RGB values in the final step, when you are ready to decode the colors as it is extremely difficult to get the numbers exactly the same for the code to work if they are entered earlier in the process.

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 Wire up your Color Sensor

In this project, you will "color-code" a secret message using your Color Sensor. First, wire up your sensor to the Raspberry Pi as shown.

Step 2 Create your function

Find the do something block under Function and drag it into your programming space. Name your function by changing "do something" to "decodeColor" as shown.

Step 3 Set up your function

Under Function, grab the if, return block and drag it underneath the to decodeColor block. This allows us to define a function that will decode letters with colors. Your code should look like the image provided.

Step 4 Define RGB values with color sensor

Click on the Data tab to view RGB values detected by the Color Sensor. Turn on the switch on the Color Sensor and make sure white light is shining from the sensor. Scan colors and note their RGB values on the bar graph provided. (Use markers to create color squares to scan. Scan the colors by pressing the paper down over the color sensor.)

Step 5 Add an RGB block

Find the RGB= block under Expansions. Drag it inside the if statement in your function. Discuss: How do RGB values represent the color you are scanning?

Step 6 Pick a color

Scan a color of your choice using the color sensor with the Data tab open. Enter the RGB values provided by the bar graph into the R, G and B parts of the RGB= block.

Step 7 What letter is that color

Find the Color Sensor block under Expansions and drag it inside of the RGB= block. Add an Alphabet block from Expansions to the return part of the statement. Change the letter to "E" using the dropdown menu. Your code should look like the image provided.

Step 8 Duplicate the condition

To add more "color coding", select the if, return block. Once highlighted, right click and select "Duplicate". Drag the duplicate blocks into the to the decodeColor function. Do this a total of 3 times. Discuss: What do these "if, return" functions do?

Step 9 Add more colors

Scan another color of your choice with the color sensor and enter the corresponding RGB values to the second RGB= block. Repeat this for the last two RGB= blocks. Each RGB= block should include values for a different color you have scanned with your color sensor.

Step 10 Add more letters

Change the Alphabet letters so that they read E, I, P, R in that order. Discuss: What do you think you will do to display each letter?

Step 11 Define what happens if no letter is found

Complete the function by adding a " " block under Variable. Drag it into the return value of the decodeColor function. We want the function to return a value when an RGB value is scanned that is not coded to return a letter. This is often called an "empty string".

Step 12 Starting the function

Find a Start block under Logic and drag it into the programming space, separate from your current code. Connect a repeat forever loop to it. Follow the image provided.

Step 13 Add a wait until block

Add a wait until block found under Chip into the repeat forever loop. Drag an = Logic block and connect to your wait until block. Change the sign to "does not equal" (≠).

Step 14 Wait until the color is right

In the "does not equal" (≠) block, drag a decodeColor under Function and an empty string (" ") so that decodeColor ≠ " ". This ensures that the computer waits until the function, decodeColor, scans a color with a coded letter before moving forward in the code.

Step 15 Add a shout color block

Find the shout color block under Chip and drag into the repeat forever loop under wait until. Add the decodeColor function block as shown.

Step 16 Start decoding

Now that your code is complete, press START in the top left corner of your screen. Try to spell "P - I - P - E - R" by scanning colors! Discuss: Which colors in what order do you need to scan with your color sensor in order to spell PIPER?

Step 1 Write you own secret code

Next, customize your code and send a secret message to a friend with color! Hint: To do this you will need to add if, return statements and/or change your Alphabet letters.

Completed!