Hackster is hosting Impact Spotlights: Industrial Automation. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Industrial Automation. Stream on Thursday!
Ryan SchmidtConnor Wardell
Created November 11, 2020

The CPX Sparkler

A sparkler engineered to allow anyone anywhere to have the fun of sparklers using technology and your imagination.

BeginnerWork in progress1 hour15
The CPX Sparkler

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Schematics

Sparkler Materials

Sparkler Long Exposure Image

Makecode used

Sparkler Build

Code

CPX Sparkler 1

JavaScript
This is the code for the left sparkler with the first 4 colors featuring white, purple, blue, and green.
input.buttonA.onEvent(ButtonEvent.Click, function () {
    light.setBrightness(10)
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
    light.setBrightness(30)
})
input.buttonsAB.onEvent(ButtonEvent.Click, function () {
    light.setBrightness(20)
})
light.setBrightness(20)
forever(function () {
    if (input.acceleration(Dimension.X) >= 300) {
        light.showRing(
        `white white white white white white white white white white`
        )
    } else if (input.acceleration(Dimension.X) <= -300) {
        light.showRing(
        `purple purple purple purple purple purple purple purple purple purple`
        )
    } else if (input.acceleration(Dimension.X) >= 300) {
        light.showRing(
        `blue blue blue blue blue blue blue blue blue blue`
        )
    } else if (input.acceleration(Dimension.X) <= -300) {
        light.showRing(
        `green green green green green green green green green green`
        )
    } else {
        light.clear()
    }
})

CPX Sparkler 2

JavaScript
This is the code for the right sparkler designed to use the 4 other colors being yellow, red, pink, and orange.
input.buttonA.onEvent(ButtonEvent.Click, function () {
    light.setBrightness(10)
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
    light.setBrightness(30)
})
input.buttonsAB.onEvent(ButtonEvent.Click, function () {
    light.setBrightness(20)
})
light.setBrightness(20)
forever(function () {
    if (input.acceleration(Dimension.X) >= 300) {
        light.showRing(
        `yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow`
        )
    } else if (input.acceleration(Dimension.X) <= -300) {
        light.showRing(
        `red red red red red red red red red red`
        )
    } else if (input.acceleration(Dimension.X) >= 300) {
        light.showRing(
        `pink pink pink pink pink pink pink pink pink pink`
        )
    } else if (input.acceleration(Dimension.X) <= -300) {
        light.showRing(
        `orange orange orange orange orange orange orange orange orange orange`
        )
    } else {
        light.clear()
    }
})

Credits

Ryan Schmidt
3 projects • 0 followers
Contact
Connor Wardell
4 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.