Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Start streaming on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Cristian Cruz
Published

Unite the Union

A interactive game that creates a new found sense of teamwork and friendship.

BeginnerProtip4 hours404
Unite the Union

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Code

Sender cpx

Makefile
network.onInfraredReceivedNumber(function (num) {
    beamedtotal = num
})
let beamedtotal = 0
let num = 0
beamedtotal = 0
let hasbeentouched = 0
let hasbeentouched2 = 0
let hasbeentouched3 = 0
let hasbeentouched4 = 0
let totaltouching = 0
forever(function () {
    if (!(input.touchA1.isPressed())) {
        hasbeentouched = 0
    } else {
        hasbeentouched = 1
    }
    if (!(input.touchA2.isPressed())) {
        hasbeentouched2 = 0
    } else {
        hasbeentouched2 = 1
    }
    if (!(input.touchA3.isPressed())) {
        hasbeentouched3 = 0
    } else {
        hasbeentouched3 = 1
    }
    if (!(input.touchA4.isPressed())) {
        hasbeentouched4 = 0
    } else {
        hasbeentouched4 = 1
    }
    totaltouching = hasbeentouched + (hasbeentouched2 + (hasbeentouched3 + hasbeentouched4))
    num = totaltouching
    network.infraredSendNumber(num)
})

Receiver CPX

Makefile
network.onInfraredReceivedNumber(function (num) {
    beamedtotal = num
})
let beamedtotal = 0
let num = 0
beamedtotal = 0
let hasbeentouched = 0
let hasbeentouched2 = 0
let hasbeentouched3 = 0
let hasbeentouched4 = 0
let totaltouching = 0
let musicmaker = 250
let ledstrip = light.createStrip(pins.A7, 30)
ledstrip.setAll(0xff0000)
forever(function () {
    if (!(input.touchA1.isPressed())) {
        hasbeentouched = 0
    } else {
        hasbeentouched = 1
    }
    if (!(input.touchA2.isPressed())) {
        hasbeentouched2 = 0
    } else {
        hasbeentouched2 = 1
    }
    if (!(input.touchA3.isPressed())) {
        hasbeentouched3 = 0
    } else {
        hasbeentouched3 = 1
    }
    if (!(input.touchA4.isPressed())) {
        hasbeentouched4 = 0
    } else {
        hasbeentouched4 = 1
    }
    totaltouching = hasbeentouched + (hasbeentouched2 + (hasbeentouched3 + hasbeentouched4))
    totaltouching = beamedtotal + totaltouching
    musicmaker = totaltouching * 125
    ledstrip.graph(totaltouching, 8)
    if (totaltouching == 8) {
        ledstrip.setGradient(0xff8000, 0xff00ff)
        music.powerUp.play()
        ledstrip.showAnimation(light.runningLightsAnimation, 2000)
        musicmaker = 250
        totaltouching = 0
        beamedtotal = 0
        num = 0
        pause(200)
        ledstrip.clear()
        light.clear()
    }
})

Credits

Cristian Cruz

Cristian Cruz

4 projects • 0 followers

Comments