1 / 4 • I connected the circuit playground express to a switch.
Fireflies and Fairies
JavaScriptFor this project, I used a Circuit Playground Express, two alligator clips, and a single joint toggle switch, and a mason jar to produce a changing light experience that represent fairies and fireflies. The alligator clips connect the playground express to the toggle switch, enabling it to switch between flashing yellow light, representing fireflies, and colorful animated lights, representing fairies. I placed the Circuit Playground Express in the lid of a mason jar, cutting out openings for the alligator clips and USB cable, and placed the mason jar on top. Wrapped around the jar is glitter covered felt paper to help spread the light throughout the jar.
The first line of code that was written for this project assigns the A1 pin to the toggle switch and whenever it is up, the lights show yellow animated lights. This animation uses the sparkle animation in MakeCode and is set to 500 milliseconds. This code also uses the forever loop, so that whenever the switch is turned down, the rainbow animation is played with a brightness of 250.
The first line of code that was written for this project assigns the A1 pin to the toggle switch and whenever it is up, the lights show yellow animated lights. This animation uses the sparkle animation in MakeCode and is set to 500 milliseconds. This code also uses the forever loop, so that whenever the switch is turned down, the rainbow animation is played with a brightness of 250.
pins.A1.setPull(PinPullMode.PullUp)
forever(function () {
if (!(pins.A1.digitalRead())) {
light.showAnimation(light.rainbowAnimation, 2000)
light.setBrightness(250)
} else {
light.showAnimation(light.sparkleAnimation, 500)
light.setAll(Colors.Yellow)
}
})



Comments