jweber76
Published

DIG3602 - Physical Computing Project 1 - "Chase"

Mini retro arcade game where you use a potentiometer to control a "cursor" that you move around the lights to the goal. Made with a CPX.

BeginnerFull instructions provided38
DIG3602 - Physical Computing Project 1 - "Chase"

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Toggle Switch, On-On
Toggle Switch, On-On
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Code

Chase Code

JavaScript
function checkGoal() {
    if (cursorPosition == goal) {
        music.magicWand.play()
        light.showAnimation(light.runningLightsAnimation, 500)
        goalSet()
    }
}
function goalSet() {
    goal = Math.floor(Math.randomRange(0, 9))
}
let pot_value = 0
let goal = 0
let cursorPosition = 0
pins.A2.setPull(PinPullMode.PullUp)
goalSet()
forever(function () {
    if (!(pins.A2.digitalRead())) {
        music.setVolume(123)
        checkGoal()
        pot_value = pins.A5.analogRead()
        cursorPosition = Math.floor(Math.map(pot_value, 0, 1023, 0, 9))
        light.setPixelColor(cursorPosition, 0xff0000)
        light.setPixelColor(goal, 0x00ff00)
        light.clear()
    } else {
        light.clear()
        music.powerDown.playUntilDone()
        music.setVolume(0)
    }
})

Credits

jweber76
4 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.