Sparkle Clothing
The code that makes your clothing light up when you move is very similar to the alarm code above. The difference is the movement detection is a bit different and uses twinkling LEDs that turn off when the movement stops.
This code uses an acceleration
range of 4g and uses the strength
readings of acceleration to read any movement in x, y, or z. If one reading is greater than another reading using some math, the sparkle is "activated" for 5 seconds. The animation can be changed from sparkle to rainbow by pressing button A, sparkle button B. You can adjust the sensitivity by changing the comparison of the variable sensitivity
. To know what is a good value you can experiment or you can use the Windows 10 version of MakeCode and see the value of the variable value
.
The animation is triggered for 5 seconds (5000
milliseconds) which may be changed in the show animation
block. Buttons A and B change the animation from sparkle to rainbow.
External NeoPixels
The example above uses internal NeoPixels on Circuit Playground Express. To animate external NeoPixels, like a strip or individual pixels, you would change the code slightly. Say there are 15 pixels connected to Circuit Playground Express pad A1.
The code would be:
This modified code creates an external strip of 15 pixels (which could be individual pixels or a physical strip or a ring) with the data line connected to Circuit Playground Express pad A1. The animation is shown on the external NeoPixels, not the onboard pixels, and when there is no significant movement the clear
NeoPixels clears the external pixels.
Buttons A and B change the animation from sparkle to rainbow.
Text editor powered by tinymce.