Motion Trigger
I want this animation to happen when I shake the dragon's head. For this, we'll use the on shake
loop from the INPUT tab.
Take a look in there and notice that there are lots of other input triggers available. You can trigger your animation with a tilt, a loud sound, a button press, or a change in ambient light, among other things. The Circuit Playground Express has a wealth of sensors and inputs to choose from to bring your puppet to life.
In the on shake
loop, we start by setting our brightness variable to our max, which will turn the LEDs on. Then we'll call our flame
function. I want my flames to last a few seconds, so I grabbed a repeat
block from the LOOPS tab. More repeats will make the flames last longer. Experiment!
Fade LEDs Out
The second repeat block is our fader. From VARIABLES, choose change bright by 0
and set the value to a negative number, to make it count down. A value of -1 will make the lights fade slowly, and a larger negative number will make the LEDs fade more quickly.
Each time this block runs in my code, the strip will dim by -2. I initially set it to 150, so running this 75 times will dim it to zero. If you want to change the dim rate, you need to also change the number of repeats so the math works out:
- Brightness 150, dim by 1: 150 repeats until we hit zero
- Brightness 150, dim by 2: 75 repeats until we hit zero
- Brightness 150, dim by 3: 50 repeats until we hit zero
Page last edited March 08, 2024
Text editor powered by tinymce.