Party Lights – Piper

PARTY LIGHTS

PIPER MAKE EDUCATOR RESOURCES SERIES

To do this project, you will need a Piper Make Starter Kit. Get yours here:

Have some fun using NeoPixel, a new kind of LED!

To get started, head to Piper Make and hit this icon:

Time: 60 minutes

Age Range: 8+

Difficulty: Advanced

This project advances students' wiring and coding skills. Students are expected to wire a series of NeoPixels, a kind of LED, and a rotary potentiometer. A series of code building steps will produce a program that uses lists, variables, loops, conditionals, sounds and actions.

Note: There are step by step instructions for the students to follow in the tutorials included in each project on Piper Make. These provide directions both for writing code and for building the electronic circuits. The tutorials are well-defined and most students will be able to follow them with little assistance required.

LEARNING OBJECTIVES

Students will:

 

  • Practice breadboarding and wiring
  • Review and understand computational concepts of:
    • loops: running the same sequence multiple times.
    • sequence: identifying a series of steps for a task
  • Create programs that include events, loops, and conditionals.
  • Decompose problems into smaller, manageable tasks which may themselves be decomposed.
  • Test and debug a program or algorithm to ensure it accomplishes the intended task.
  • Perform different roles when collaborating with peers during the design, implementation, and review stages of program development.

STANDARDS ALIGNMENT

CSTA's K-12 Standards 

1B-AP-09 Create programs that use variables to store and modify data. Subconcept: Variables; Practice 5.2

1B-AP-10 Create programs that include sequences, events, loops, and conditionals. Subconcept: Control; Practice 5.2

1B-AP-11 Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process. Subconcept: Modularity; Practice 3.2

1B-AP-12 Modify, remix, or incorporate portions of an existing program into one’s own work, to develop something new or add more advanced features. Subconcept: Modularity; Practice 5.3

1B-AP-15 Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended. Subconcept: Program Development; Practice 6.1, 6.2

CCSS ELA

CCSS.ELA.L.W.3.8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

CCSS.ELA.L.W.3.10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

World-Class Instructional Design and Assessment (WIDA) English Language Proficiency Standards

ELD-SI.K-3.Argue:

  • Ask questions about others’ opinions
  • Support own opinions with reasons
  • Clarify and elaborate ideas based on feedback
  • Defend change in one’s own thinking
  • Revise one’s own opinions based on new information

 

ELD-SC.2-3.Argue.Interpretive:

  • Interpret scientific arguments by
  • Identifying potential evidence from data, models, and/or information from investigations of phenomena or design solutions
  • Analyzing whether evidence is relevant or not
  • Distinguishing between evidence and opinions

California's K-12 Computer Science Standards

3-5.AP.11 Create programs that use variables to store and modify data.

3-5.AP.12 Create programs that include events, loops, and conditionals.

3-5.AP.13 Decompose problems into smaller, manageable tasks which may themselves be decomposed.

3-5.AP.14 Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features.

3-5.AP.17 Test and debug a program or algorithm to ensure it accomplishes the intended task.

Common Core English Language Arts

CCSS.ELA.L.W.3.8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

CCSS.ELA.L.W.3.10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

California English Language Development Standards

CA ELD.3.C.11: Supporting own opinions and evaluating others’ opinions in speaking and writing

CA ELD.3.C.12: Selecting and applying varied and precise vocabulary and language structures to effectively convey ideas

Michigan Integrated Technology Competencies for Students (MITECS)

1B-AP-09 Create programs that use variables to store and modify data. Subconcept: Variables; Practice 5.2

1B-AP-10 Create programs that include sequences, events, loops, and conditionals. Subconcept: Control; Practice 5.2

1B-AP-11 Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process. Subconcept: Modularity; Practice 3.2

1B-AP-12 Modify, remix, or incorporate portions of an existing program into one’s own work, to develop something new or add more advanced features. Subconcept: Modularity; Practice 5.3

1B-AP-15 Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended. Subconcept: Program Development; Practice 6.1, 6.2

Michigan English Language Arts

Michigan ELA, Grade 3-8, Research, 8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

Michigan ELA, Grade 3-8, Range of Writing, 10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

WIDA English Language Development

ELD-SI.K-3.Argue:

  • Ask questions about others’ opinions
  • Support own opinions with reasons
  • Clarify and elaborate ideas based on feedback
  • Defend change in one’s own thinking
  • Revise one’s own opinions based on new information

 

ELD-SC.2-3.Argue.Interpretive:

  • Interpret scientific arguments by
  • Identifying potential evidence from data, models, and/or information from investigations of phenomena or design solutions
  • Analyzing whether evidence is relevant or not
  • Distinguishing between evidence and opinions

Science Texas Essential Knowledge & Skills Grade 3

(b)(2) Scientific investigation and reasoning. The student uses scientific practices during laboratory and outdoor investigations. The student is expected to:
(A) plan and implement descriptive investigations, including asking and answering questions, making inferences, and selecting and using equipment or technology needed, to solve a specific problem in the natural world;

(b)(3) Scientific investigation and reasoning. The student knows that information, critical thinking, scientific problem solving, and the contributions of scientists are used in making decisions.

Science Texas Essential Knowledge & Skills Grade 4

(a)(1)(A) Within the physical environment, students know about the physical properties of matter including mass, volume, states of matter, temperature, magnetism, and the ability to sink or float. Students will differentiate among forms of energy including mechanical, light, sound, and thermal energy. Students will explore electrical circuits and design descriptive investigations to explore the effect of force on objects.

(b)(3) Scientific investigation and reasoning. The student uses critical thinking and scientific problem solving to make informed decisions. The student is expected to:

    (A) analyze, evaluate, and critique scientific explanations by using evidence, logical reasoning, and experimental and observational testing;

    (B) represent the natural world using models such as the water cycle and stream tables and identify their limitations, including accuracy and size; and

    (C) connect grade-level appropriate science concepts with the history of science, science careers, and contributions of scientists.

Science Texas Essential Knowledge & Skills Grade 5

(a)(1) In Grade 5, scientific investigations are used to learn about the natural world. Students should understand that certain types of questions can be answered by investigations and that methods, models, and conclusions built from these investigations change as new observations are made. Models of objects and events are tools for understanding the natural world and can show how systems work. They have limitations and based on new discoveries are constantly being modified to more closely reflect the natural world.

(a)(3) Recurring themes are pervasive in sciences, mathematics, and technology. These ideas transcend disciplinary boundaries and include patterns, cycles, systems, models, and change and constancy.

ELA Texas Essential Knowledge & Skills Grade 3

(b) (1)Developing and sustaining foundational language skills: listening, speaking, discussion, and thinking--oral language. The student develops oral language through listening, speaking, and discussion. The student is expected to:

    (A) listen actively, ask relevant questions to clarify information, and make pertinent comments;

    (B) follow, restate, and give oral instructions that involve a series of related sequences of action;

    (C) speak coherently about the topic under discussion, employing eye contact, speaking rate, volume, enunciation, and the conventions of language to communicate ideas effectively;

    (D) work collaboratively with others by following agreed-upon rules, norms, and protocols; and

    (E) develop social communication such as conversing politely in all situations.

ELA Texas Essential Knowledge & Skills Grades 4 & 5

(b) (1)Developing and sustaining foundational language skills: listening, speaking, discussion, and thinking--oral language. The student develops oral language through listening, speaking, and discussion. The student is expected to:

    (A) listen actively, ask relevant questions to clarify information, and make pertinent comments;

    (B) follow, restate, and give oral instructions that involve a series of related sequences of action;

    (C) express an opinion supported by accurate information, employing eye contact, speaking rate, volume, enunciation, and the conventions of language to communicate ideas effectively; and

    (D) work collaboratively with others to develop a plan of shared responsibilities.

(b)(13) Inquiry and research: listening, speaking, reading, writing, and thinking using multiple texts. The student engages in both short-term and sustained recursive inquiry processes for a variety of purposes. The student is expected to:

    (A) generate and clarify questions on a topic for formal and informal inquiry;

    (B) develop and follow a research plan with adult assistance;

    (C) identify and gather relevant information from a variety of sources;

    (D) understand credibility of primary and secondary sources;

    (E) demonstrate understanding of information gathered;

    (F) differentiate between paraphrasing and plagiarism when using source materials;

    (G) develop a bibliography; and

    (H) use an appropriate mode of delivery, whether written, oral, or multimodal, to present results.

§74.4. English Language Proficiency Standards

(c) Cross-curricular second language acquisition essential knowledge and skills.

(3) Cross-curricular second language acquisition/speaking.

(D) speak using grade-level content area vocabulary in context to internalize new English words and build academic language proficiency;

(E) share information in cooperative learning interactions;

(F) ask and give information ranging from using a very limited bank of high-frequency, high-need, concrete vocabulary, including key words and expressions needed for basic communication in academic and social contexts, to using abstract and content-based vocabulary during extended speaking assignments;

(G) express opinions, ideas, and feelings ranging from communicating single words and short phrases to participating in extended discussions on a variety of social and grade-appropriate academic topics;

(H) narrate, describe, and explain with increasing specificity and detail as more English is acquired;

CONCEPTS

In this project, students will expand their understanding of the concept of sequences in loops by creating code that produces sounds and a cascade of different colored lights.

PARTS

  • Pico and Breadboard
  • 8 M2M Jumper Wires
  • 3 M2F Jumper Wires
  • 5 NeoPixel LEDs
  • 1 Rotary Potentiometer
  • 1 Slide Potentiometer

GPIO SETUP

OVERVIEW OF STEPS

Step 1: Who doesn't like to have some fun?

It's time to throw a party! In this tutorial, we are going to have some fun with lights and sounds. We are going to use a new kind of LED called a NeoPixel.

A NeoPixel is a smart LED that has green, blue, and red light, along with a controller all inside that can make the LED glow any color we want!

We are also going to learn about potentiometers. Potentiometers are resistors that we can change the value of by sliding or turning them. We can use them to easily control our circuit.

Ready to get started? Click NEXT.

Step 2: Grab your stuff

You will need:

  • Pico and Breadboard
  • 8 M2M Jumper Wires
  • 3 M2F Jumper Wires
  • 5 NeoPixel LEDs
  • 1 Rotary Potentiometer
  • 1 Slide Potentiometer

Step 3: What is a NeoPixel?

The LEDs you are using are special because they can shine in any color that you program to! They are called NeoPixels.

NeoPixels are actually 3 different LEDs (1 red, 1 green, and 1 blue) and a special chip all packed in a single package. In fact, if you were able to break open a NeoPixel and look at it under the microscope, this is what you would see:

You probably also noticed that the NeoPixel has four leads instead of the the normal two. That's because it need two for power and ground, just like any other LED, but it needs one lead for a data in signal, and another to send data out to the next NeoPixel:

NeoPixels are meant to be chained together. That means that you connect the output of one NeoPixel to the input of the next NeoPixel.

Ready to build your NeoPixel circuit? Click NEXT.

Step 4: Begin building your circuit

The first thing we are going to do is add the NeoPixels to the Breadboard.

It works best if you spread the leads of the NeoPixel out a little bit first. Look carefully at the image below. Make sure that as you are connecting the NeoPixels to the breadboard, they are oriented correctly!

The longest lead is going to go into the ground rail at the top of the breadboard. The other middle lead will connect to the 5V rail at the top of the breadboard. The leftmost lead will connect into a column on the breadboard, and the rightmost lead will connect to a different breadboard column:

Repeat this process for each of the remaining NeoPixels. Remember that the output of one NeoPixel connects to the input of the next Neopixel.

Then, use a jumper wire to connect the input of the first NeoPixel's Input to GP15.

Next, connect the top power rails. Use a jumper wire to connect the top ground rail to a ground pin on the Pico. Use another jumper to connect the top positive rail to 5V.

Click NEXT.

Step 5: What is a Potentiometer?

Your kit contains two different kinds of potentiometers. There is a rotary potentiometer, which can detect what position you turn it to, and a slide potentiometer, which can detect which position you slide it to.

Look carefully at the diagram below.

Do you remember doing the Resistor Piano tutorial? In that tutorial, you learned about voltage dividers. A potentiometer can be wired up in the same way, and it can become a voltage divider!

Notice that both potentiometer's have three connections. The middle connection on the rotary potentiometer, and the one labeled OTA or OTB is connected to the potentiometer's wiper. The wiper makes contact with a resistive material like carbon or graphite - which acts like a resistor. Depending on where along the length of the resistive material the wiper makes contact, the resistance changes.

Ready to connect the potentiometers to your circuit? Click NEXT.

Step 6: Finish building your circuit

First, use a jumper wire to connect the bottom ground rail to another ground pin on the Pico. Connect the bottom positive rail on the breadboard to the 3V pin on the Pico.

Then, place the rotary potentiometer somewhere in the bottom half of your breadboard. Pay attention to which 3 columns the leads of the potentiometer plug into. Then, use a jumper wire to connect the rightmost lead to the positive rail on the bottom of the breadbaord. Connect another jumper from the leftmost lead to the ground rail on the bottom of the breadboard. Finally, connect a jumper wire from the center lead of the potentiometer to the A0 pin on the Pico.

Next, connect a M2F jumper wire from the GND pin on the slide potentiometer to the ground rail on the bottom of the breadboard. Connect another 2F jumper wire from the VCC pin to the positive rail on the bottom of the breadboard. Finally, connect a M2F jumper wire from the OTA pin on the slide potentiometer to pin A1 on the Pico.

That's it! double check all of your connections, and then, click NEXT.

Step 7: Test the potentiometers

Now that our potentiometers are connected, let's build some code that we can use to test them.

Grab a start block from the Chip menu and place it onto the workspace. Then, grab a repeat forever block from the Loops menu and connect to the start block.

Next, grab a graph block from the Actions menu and place it into the repeat forever block. Click the Blue Gear Icon on the graph block. In the mini-workspace that opens up, drag a value block into the send block so that there are two blocks inside of it. Click the blue gear icon again to close the mini-workspace:

Grab a read voltage from block from the Chip menu and place it into the first input of the graph block. Grab another read voltage from block from the Chip menu and place it into the second input of the graph block. On the second read voltage from block, change the pin to A1:

You're almost ready to test out the potentiometers!

Make sure your Pico is connected to your computer. Click the DATA tab at the bottom of the workspace to open the graph. Then, click CONNECT. Select your Pico from the menu that pops up. Once your Pico is connected, click START.

Turn the knob on your rotary potentiometer, and move the slider on your slide potentiometer. What happens to the lines on the graph when you do that?

If your potentiometers are working correctly, the slider should move the blue line up and down, and the knob should move the teal line up and down.

Click STOP when you are ready to move on. Then, click the DATA tab to close the graph, and then click NEXT.

Step 8: Test the NeoPixels

Now that we have tested the potentiometers, let's test the NeoPixels.

First, grab the graph block in your program and drag it to the trash.

Next, grab the setup neopixels block from the Actions menu and connect it between the start and the repeat forever blocks. Change the pin to 15, and set the number of pixels to 5:

Grab a set all neopixels to block from the Actions menu and place it inside the repeat forever block. Grab the color block that is inside of the set all neopixels to block and drag it to the trash can to delete it. Grab a random color block from the Values menu and place it inside the set all neopixels to block. Finally, grab a update neopixels block from Actions and connect it below the set all neopixels to block:

Before you click START - be careful not to stare directly into the NeoPixels - they can be VERY BRIGHT!
Click START to run your test program. Do the NeoPixels flash different colors every 0.5 seconds? Awesome!

Once your NeoPixels are working, click STOP.

But wait! Why are the NeoPixels still on? NeoPixels will stay on the last color that the Pico sent to them. One way to turn them off is to send them a black color using the color block from the Values menu:

Click START again to turn the NeoPixels off. Then click STOP, then click NEXT.

Step 9: Twist for color!

Let's use the knob to set the color of the NeoPixels. We can do this by mapping the value that we get from reading the voltage from pin A1 to a value block named color hue.

The color hue block turns any number value from 0 to 255 to a color by changing it's hue.

What is Hue? There are several ways to think about color. If you've completed the Color Sensor tutorial, you learned about how Red, Green, and Blue light can be mixed to create different colors. Our eyes also detect color by sensing the amount of red, green, and blue in the light that our eyes see.

Another way to think about color is in terms of hue, saturation, and brightness. Hue is the color, saturation is how "deep" the color is, and brightness refers to its intensity. Look at the image below to compare RGB and HSB:

The color hue block will turn a number value into a Hue. Let's try it out!

First, let's turn the Digital View off by clicking the DIGITAL VIEW tab at the bottom of the workspace to open it. Then, click the toggle switch on the left side of the digital view to turn it off. Then, click the DIGITAL VIEW tab again to close it.

Why did we just do that? When the digital view is running, it slows the Pico down a little, and it can actually slow down your computer too, because the computer has to listen for messages from the Pico.

Our next task to to make a variable that will hold the value that we will turn into a color. Click the Variables menu, and then click Create variable.... Name your new variable "knob value". Then grab the set knob value block and place it at the top inside of the repeat forever block:

Since we know we need to map the value from the rotary potentiometer to a new value between 0 and 255, we'll need a map value block.

Grab a map value block from the Logic menu and place it into the first input of the map value block. Set the from range to 0 : 3.3. This is because the voltage that can come from the potentiometer will be between 0 and 3.3V.

Then, change the to range to 0 : 255. Grab a read voltage from block and place into the empty input of the map value block. Set the pin to A1:

Next, grab the color block inside of the set all neopixels to block and drag it to the trash can to delete it. Grab a color hue block from the Values menu and place it where you just removed the color block from. Grab the 0 block from inside the color hue block and drag it to the trash can to delete it.

Next, grab a knob value block from the Variables menu and place it into the color hue block. Then, set the wait time of the repeat forever block to 0:

Click START to try it out. Turn the knob to see how the color of the NeoPixels change. Once you have tried it out, click STOP, then click NEXT.

Step 10: Slide for brightness

Let's use the slide potentiometer to adjust the brightness. Just like we used the knob to adjust the hue.

Click the Variable menu and then click Create variable... Name your new variable "slide value".

Right-click the set knob value block and select Duplicate. Connect the new blocks right below the blocks you just copied. Change the variable to slide value and set the pin in the read voltage from block to A0. Then, set the to range in the map value block to 0 : 100. Grab the 100 block from inside the color hue block and drag it to the trash can to delete it. Grab a slide value block from the Variables menu and place it into the input you just removed the 100 block from:

Give it a try again! Click START to run your code. Slide the slide potentiometer and turn the knob on the rotary potentiometer to see what colors you get!

When you are ready to move to the next step, click STOP, and then click NEXT.

Step 11: Rainbow chase

Now that we can make any color we want, let's try making a rainbow chase! A rainbow chase is where we set each light to a different color, and then make the lights look like they are "chasing" each other. It's a really cool effect, and it's not too hard to do!

The first thing we need is a list to store 5 different colors in, and we need a variable to hold that list.

Click the Variables menu and then click Create variable.... Name your new variable "color list". Grab the set color list to block and connect it right below the setup neopixels block near the beginning of your program.

Grab a create list with block from the Lists menu and place it into the set color list block. Then, click the blue gear icon to open the block's mini-workspace. Drag and add two more item blocks in the mini workspace so that you have a total of 5, and then click the blue gear icon to close the mini-workspace:

Now we need to fill our list with colors. Grab a 0 block from the Values menu and place it into the first input of the create list with block. Do this again 4 more times to fill all of the inputs of the create list with block.

Set the 0 block's value to 0. Set the next one's to 50, the middle one's to 100, the next one's to 150, and the last one's to 200. Why these values? The range of values you can put into the color hue goes from 0 to 255. If you divide 255 by 5, you get 51. 50 is close enough, so that is why each value is 50 more than the next!

Click the set all neopixels block so that it is highlighted (there is a yellow ring around it) and press your "delete" or "backspace" key to delete that block.

Grab a count with block from the Loops menu and place it into our program right before the update neopixels block. Change the 10 in that block to a 5.

Then, grab a set neopixel block from the Actions menu and place it inside the count with block. Delete both of the blocks that are inside of the set neopixel block:

Grab an i block from the Variables menu and place it into the first input of the set neopixel block. Then, grab a color hue block from the Values menu and place it into the second input of the set neopixel block.

Delete the 0 and 100 blocks from the color hue block by dragging them to the trash can. Then, grab a in list block from the Lists menu and place it into the hue input of the color hue block. Grab a slide value block from Variables and place it into the brightness input of the color hue block:

Step 12: Almost there...

Grab a color list block from Variables and place it into the first input of the in list block. Then, grab another i block from Variables and place it into the second input of the in list block:

Let's try it out! Click the START button. If it's working, each of the NeoPixels will glow a different color, and we can use the slide potentiometer to adjust their brightness.

They aren't "chasing", though...how do we make them chase?

We are going to use a rotate list block! When you rotate a list, you take the value from one end and attach it to the other, and shift all of the other items in the list. You can rotate left or right. The image below shows what happens to a list when it is rotated 1 position to the left:

Grab a set i to block from the Variables menu and connect it right below the update neopixels block. Change the i to color list. Grab a rotate list block from the Lists menu and place it into the input of the set color list to block. Then, grab a color list block from Variables and place it into the first input of the rotate list block. This will rotate the color list, so the next time the neopixels are updated, the color each one is displaying will shift 1 neopixel over.

Since we aren't going to use the knob to set the color any more, let's use it to adjust how fast the neopixels "chase".

Grab the 0 block from the wait time on the repeat forever block and drag it to the trash can to delete it. Then, grab a knob value block from the Variables menu and place it into the wait input of the repeat forever block.

Find the map value block inside of the set knob value to block. Change the to range to 0.8 : 0.1:
Try it out! Click START to run your program. Slide the slide potentiometer to change the brightness of the NeoPixels, and turn the knob on the rotary potentiometer to speed up or slow down the chase of the colors.

Now that we have lights, let's add some sound! Click STOP, then click NEXT.

Step 13: A list of sounds

Let's make another list. This list is going to hold our sounds. We also need a variable to hold our list.

Click the Variables menu and then click Create variable.... Name your new variable "sound list".

Right-click the set color list block at the beginning of your program and select Duplicate. Connect the new blocks right below the first set color list block. Then change the variable in that block to sound list. Delete the 50, 100, 150, and 200 blocks in that block's create list with block by dragging them to the trash can (leave the 0 block in the list). Next, grab a drumkit block from the Sounds menu and place it into of the inputs of the create list with block. Do this again for all of the empty inputs. Then, pick a different option for each drumkit block:

Grab an if _ = _ do block from the Logic menu and connect it after the set color list block at the end of your program. Grab an in list block from the Lists menu and place it into the first input of the _ = _ block. Change the # in the in list block to first. Then, grab a sound list block from Variables and place it into the input of the in list block. Change the = in the _ = _ block to (not equal). Then, grab a 0 from Values and place it into the right side of the _ _ block.

This will make it so that when it gets to the 0 in our list of sounds, it will just not play a sound. That means we can have "rests", which make our beats sound better!

Grab a play sound block from the Sounds menu and place it inside the if do block. Right-click the in list block in the if do block and select Duplicate. Place the new blocks in the input of the play sound block.

Right-click the set color list block right above the if do block and select Duplicate. Place the new block after the if do block. Change the variables in the new blocks (both of them) to sound list. Then, change the 1 in the left by input to -1:

Step 14: Try it out!

Give it a try by clicking START. It's a party, right!?

Once you are done dancing to the lights and sounds, click STOP.

Now, for some new challenges! Try to see if you can do these with your Party Lights circuit:

  • Add another track of sounds
  • add a different light pattern
  • Use the slide potentiometer to change the sounds or notes



Give these challenges a try!

Click NEXT.

Step 15: You've Finished!

Click EXIT to return to the menu and start your next coding challenge.