Created
April 13, 2018 13:44
-
-
Save netom/76625db5e3f8d3bea60710367fd7fd96 to your computer and use it in GitHub Desktop.
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 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