Nous utilisons des cookies pour offrir à nos clients une expérience optimale du site. Consultez notre avis de confidentialité et notre avis relatif aux cookies pour en savoir plus sur la manière dont nous utilisons les cookies et sur la gestion de vos paramètres. En accédant à notre site Web, vous consentez à l'utilisation de cookies.
Construction paper, glitter glue, foil door curtain (for decorations)
Popsicle stick for spreading glitter glue.
Program with MakeCode
What is MakeCode?
MakeCode is a web-based code editor for physical computing made by Microsoft.
On start, set the volume of the CPX speaker, set the variable play to 0, then set all the NeoPixels to red.
In a forever loop, we check to see if the variable play is set to 1. If it is, call the song function to play the tune "Auld Lang Syne" then set play to 0. As it's a forever loop, this code block loops forever regardless of other events that happen in the code!
An abbreviated version of the song The "Auld Lang Syne" can be separated into 2 parts. The tune starts with part 1, then goes to part 2, before repeating again. Creating functions for these song parts then "calling" the functions later allows us to have much cleaner looking and more organized code. It also allows us to reduce the amount of code needed for the project making the program more efficient (more on that in the next code block).
When the CPX is shaken, we call the function countingdown, set the variable play to 1, turn the NeoPixels rainbow, turn the servo clockwise for 3 seconds, pause the servo for 15 seconds, turn the servo counter-clockwise for 3 seconds then turn the NeoPixels back to all red.
In the countingdown function, we want to count the NeoPixels down one at a time, per second, from all red to all white. To do this with out making the code clunky, we can use something called a while loop. First, the NeoPixels are set to all red, then the variable countdown is set to 9. In the while loop, as long as the variable countdown is greater than or equal to 0, each concurrent NeoPixel will change from red to white, every second. In each iteration of the loop, countdown is decremented by 1 until it reaches -1 at which point the program will exit the function and continue with the rest of the code to play the song and turn the servo.
In the on shake code block, the piece of code that says "Servo write pin A1 to (value between 0 and 180)" determines how fast or slow and what direction the servo spins. Values between 0 and 90 spin the servo clock wire and 90 - 180 is counter clockwise. The closer the values are to 90, the slower the servo will spin in either direction.
Uploading the Code
Now that we have the code for the project, we need to upload it to the CPX.
Let's name our file and download it.
Choose a name at the bottom of the page.
Then click the pink Download button.
Follow the directions and connect your CPX to your computer via the usb cable. Click the CPX Reset button once to go into programming mode (all NeoPixels will turn green).
In some cases, you may need to press the reset button twice to get into programming mode.
Next, look for the file in your downloads folder and drag it onto your CPLAYBOOT drive that should have showed up in your file manager/finder when you plugged in your board and entered programming mode.
You should now see the CPLAYBOOT drive disappear.
The code should now be running and the NeoPixels should be all red. Before we test it out let's wire up the servo!
Before we build the mechanism we'll first wire up the electronics to make sure everything is working correctly. This will also help us get a handle on how the electronics will work in tandem with the cardboard and string components.
Take the continuous servo's cable and plug in corresponding cable to CPX: Orange/yellow goes to A1 on the CPX, red to VOUT, brown/black to GND*
Connect the battery to the CPX via the JST connector.
* If you have the alligator clip to jumper wires this will be possible. If you only have wires, skip ahead to "Prep and Mount Electronics" section for how to wire the project with these components. I didn't have those specific components so I used alligators clips and attached them to jumper wires which works just fine as well for testing out the electronics.
The code should now be running so try it out!
When the board is powered up, the NeoPixels on the CPX should turn red.
When you shake the CPX, the NeoPixels should begin counting down turning clock-wise from red to white one NeoPixel every second.
When the last NeoPixel turns white, NeoPixels turn into a rainbow pattern, the servo turns for 3 seconds and the "Auld Lang Syne" song comes on.
After the servo is done turning the CPX should continue playing the song with rainbow NeoPixels until the song finishes.
After a couple more seconds, the servo should turn the other way for about 3 seconds, then the NeoPixels should turn red again ready to restart the process.
If you are having issues getting things to work check out this extended guide here.
Build the Base and Mount
Using hobby knives or other sharp cutting instruments should be supervised for younger Makers.
Use a hobby knife or box cutter to cut out a sheet of cardboard sized 22 cm X 14 cm.
Glue a paper towel roll center to one end of cardboard sheet.
Cut (or break with hands) a bamboo skewer to be roughly 17 cm long. Keep the pointy side as part of the piece.
Glue on top of the roll center with the pointy side facing towards the length of the sheet. Leave a couple of centimeters of skewer to hang off the back.
Use a string, a thumb tack and a pencil to draw a circle on some cardboard with a diameter of 8 cm. Tie the string to the thumb tack then measure a distance of 4 cm from the tack to a pencil and tie around pencil tip. Use the tack to guide the pencil around a circle. You may need to lay some extra cardboard underneath so that the tack can firmly rest in the cardboard without moving too much.
Next, measure and draw two small rectangles sizes 2 cm X 3 cm.Use a hobby knife to cut out these pieces.
Orient the servo so that the brown wire is facing upward. Glue the small rectangular pieces on the sides of the servo with the 3 cm lengths sticking out.
Make the Spool
Measure and draw a rectangle on some cardboard sized 1 cm x 8 cm. Draw a line at every 2 cm point along the rectangle.
Measure and draw a circle with a 4 cm diameter using the same string and thumb tack technique from earlier.
Cut out the parts.
On the rectangular piece, score along 2 cm lines.
Bend and fold into square and glue onto one circle piece.
Glue the other circle on top.
Cut a string roughly 45 cm long and glue one end to spool.
Wrap the string around the spool.
Glue servo wing on the side of the spool making sure the spool is oriented such that the string is coming up and out to the right.
Draw perpendicular lines through each side of the 8 cm circle.
Attach servo onto wing and spool.
Orient the spool and servo contraption on the 8 cm circle base such that the spool is centered. Double check that the string is facing towards the circle base top where it will be pulled through shortly.
Glue down spool and servo contraption on circle base.
On the front of the circle base, use a hobby knife to cut a hole in the top center.
Pull spool string through hole.
Prep and Mount Electronics
Use wire strippers to remove 1-2 cm of wire wrap from ends of each wire.*
If using stranded core, twist wires together.
*I used jumper wires because solid core wires we're unavailable but the process is the same!
Pull black wire through GND and twist around to create a tight connection.
Repeat with red wire to VOUT and yellow to A1.
Connect other ends of wire to servo cable. Yellow/A1 to orange, red/VOUT to red, black/GND to brown.
Put piece of duct tape in center of front side of circle base.
Place CPX in center of tape.
In order to counter balance the weight from the servo and spool which are on the right side of the back of the circle base, we need to place the battery on the other side.
Put a piece of tape on the left side of the back of the circle piece and place the battery down with the wires facing the bottom.
Gather / organize wires together and tape down.
Insert JST connector from battery into CPX.
Loosely tie a knot in the string.
Place skewer though hole of knot and pull tight.
Test it out!
Try shaking the CPX and see what happens. If the CPX doesn't fall/rise enough or falls/rises too far, go back to MakeCode and edit the on shake code block. Remember, the piece of code that says "Servo write pin A1 to (value between 0 and 180)" can be edited to change the speed of the servo.
Remove CPX from front of circle base.
Use a popsicle stick to spread glitter glue on the front of the circle base.
Remove some glue from the center where CPX will get taped back later.
Spread another color of glitter glue on the paper towel core. Two layers may be preferable.
Add whatever decorations you want! I followed the roll's line with a different color glitter glue.
Draw the block letter numbers of what ever year you are celebrating.
Cut 'em out.
Attach to glitter glue on front circle base.
Feel free to add glitter glue to the numbers if you'd like!
At this point you may want to let glitter glue dry over night!
Using some shiny door hanger material, glue to back of circle base so the pieces are hanging off.
Place the CPX back in the center and plug in the battery.
Holding the contraption up, cut off extraneous hanging pieces.