Skip to content

Instantly share code, notes, and snippets.

@nbogie
Last active October 30, 2017 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbogie/142e607c645771aa7f526f07ce0ebe42 to your computer and use it in GitHub Desktop.
Save nbogie/142e607c645771aa7f526f07ce0ebe42 to your computer and use it in GitHub Desktop.
Scorer for micro:bit reaction game. Uses servo to display score.
let angle = 0
radio.onDataPacketReceived( ({ receivedNumber }) => {
if (receivedNumber < 0) {
basic.showIcon(IconNames.Angry)
} else {
pins.servoWritePin(AnalogPin.P2, pins.map(
3000 - Math.min(receivedNumber, 3000),
0,
3000,
5,
175
))
basic.showNumber(receivedNumber)
if (receivedNumber < 2) {
doFastHandsAlarm()
}
}
})
input.onButtonPressed(Button.B, () => {
angle += 10
if (angle > 175) {
angle = 5
}
pins.servoWritePin(AnalogPin.P2, angle)
radio.sendNumber(angle)
})
function doFastHandsAlarm() {
basic.pause(1000)
basic.showIcon(IconNames.Fabulous)
basic.pause(2000)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
}
input.onButtonPressed(Button.A, () => {
radio.sendNumber(Math.random(2701))
})
radio.setGroup(44)
@nbogie
Copy link
Author

nbogie commented Oct 30, 2017

Changed range of the scorer to 0ms - 3000ms so that very young or slower kids still chart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment