Skip to content

Instantly share code, notes, and snippets.

@will-moore
Created November 7, 2017 23:55
Show Gist options
  • Save will-moore/483bf4ab1c54dc4335cc09640876296c to your computer and use it in GitHub Desktop.
Save will-moore/483bf4ab1c54dc4335cc09640876296c to your computer and use it in GitHub Desktop.
Micro-bit code for bit-bot controlled via remote
let bend = 0
let speed = 0
radio.onDataPacketReceived( ({ receivedString: name, receivedNumber: value }) => {
if (name == "bend") {
basic.showLeds(`
. . . . .
. # . # .
# # # # #
. # . # .
. . . . .
`)
basic.pause(100)
bend += value
}
if (name == "speed") {
speed += value
basic.showLeds(`
. . # . .
. # # # .
. . # . .
. # # # .
. . # . .
`)
basic.pause(100)
}
})
input.onGesture(Gesture.TiltLeft, () => {
radio.sendValue("bend", 10)
basic.showLeds(`
. . . . .
. # . . .
# # # # #
. # . . .
. . . . .
`)
basic.pause(500)
})
input.onButtonPressed(Button.A, () => {
radio.sendValue("speed", -50)
basic.showLeds(`
. . . . .
. . . . .
# # # # #
. . . . .
. . . . .
`)
basic.pause(500)
})
input.onGesture(Gesture.TiltRight, () => {
radio.sendValue("bend", -10)
basic.showLeds(`
. . . . .
. . . # .
# # # # #
. . . # .
. . . . .
`)
basic.pause(500)
})
input.onButtonPressed(Button.B, () => {
radio.sendValue("speed", 50)
basic.showLeds(`
. . # . .
. . # . .
# # # # #
. . # . .
. . # . .
`)
basic.pause(500)
})
speed = 0
bend = 0
basic.showIcon(IconNames.Heart)
basic.forever(() => {
basic.showNumber(bend)
bitbot.motor(BBMotor.Left, speed + bend)
bitbot.motor(BBMotor.Right, speed - bend)
basic.pause(100)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment