Skip to content

Instantly share code, notes, and snippets.

@netom
Created April 13, 2018 13:44
Show Gist options
  • Save netom/76625db5e3f8d3bea60710367fd7fd96 to your computer and use it in GitHub Desktop.
Save netom/76625db5e3f8d3bea60710367fd7fd96 to your computer and use it in GitHub Desktop.
let distance = 0
bluetooth.onBluetoothConnected(() => {
basic.showLeds(`
. # # . .
. # . # .
. # # . .
. # . # .
. # # . .
`)
})
bluetooth.onBluetoothDisconnected(() => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
})
sbrick.onConnected(() => {
basic.showLeds(`
. # # # .
. # . . .
. . # . .
. . . # .
. # # # .
`)
sbrick.setDevice(SBConnectedDevice.Wedo1Motion, SBPort.C)
})
sbrick.onMeasurement(() => {
distance = sbrick.measuredValue() - 200
led.plotBarGraph(
distance,
220
)
if (distance <= 100) {
sbrick.drive(255, SBPort.D, SBDirection.Forward)
} else {
sbrick.brake(SBPort.D)
}
})
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
sbrick.connect("SBrick1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment