Jeffrey FoxLylly HoangRandall ForehandNora Barnes
Published

Light Tag With CPX

With this project we were looking to use multiple cpx units to make a fun game of light tag.

IntermediateWork in progress1 hour418
Light Tag With CPX

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Adafruit NeoPixel Digital RGB LED Strip - White 30 LED - WHITE
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Code

Light Tag with CPX

JavaScript
This code was made in make code and exported into javascript. An external LED strip was also connected to the CPX.
let strip: light.NeoPixelStrip = null
let strip2: light.NeoPixelStrip = null
let light2 = 0
let currentColor = 0
input.buttonA.onEvent(ButtonEvent.Click, function () {
strip.setAll(0xff0000)
light.setPixelColor(3, 0xff0000)
light.setPixelColor(4, 0xff0000)
light.setPixelColor(5, 0xff0000)
light.setPixelColor(6, 0xff0000)
light.setPixelColor(7, 0xff0000)
light.setPixelColor(8, 0xff0000)
})
input.onSwitchMoved(SwitchDirection.Left, function () {
strip2.setAll(0xff0000)
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
strip.setAll(0x00ff00)
light.setPixelColor(3, 0x00ff00)
light.setPixelColor(4, 0x00ff00)
light.setPixelColor(5, 0x00ff00)
light.setPixelColor(6, 0x00ff00)
light.setPixelColor(7, 0x00ff00)
light.setPixelColor(8, 0x00ff00)
})
input.onSwitchMoved(SwitchDirection.Right, function () {
strip2.setAll(0x00ff00)
})
forever(function () {
strip = light.createStrip(pins.A1, 21)
strip2 = light.createStrip(pins.A2, 6)
light2 = input.lightLevel()
strip.setBrightness(255)
console.logValue("x", input.lightLevel())
if (input.lightLevel() > 20) {
currentColor = input.ambientColor()
strip.setAll(currentColor)
light.setPixelColor(6, currentColor)
light.setPixelColor(7, currentColor)
light.setPixelColor(8, currentColor)
light.setPixelColor(3, currentColor)
light.setPixelColor(4, currentColor)
light.setPixelColor(5, currentColor)
music.baDing.playUntilDone()
pause(5000)
}
})

Credits

Jeffrey Fox
4 projects • 0 followers
Contact
Lylly Hoang
4 projects • 0 followers
Contact
Randall Forehand
4 projects • 0 followers
Contact
Nora Barnes
3 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.