Last active
October 30, 2017 00:40
-
-
Save nbogie/142e607c645771aa7f526f07ce0ebe42 to your computer and use it in GitHub Desktop.
Scorer for micro:bit reaction game. Uses servo to display score.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changed range of the scorer to 0ms - 3000ms so that very young or slower kids still chart.