Created
December 22, 2016 21:46
-
-
Save yratof/cbdd193c61f7f439ee60ba1a5d1dd88c to your computer and use it in GitHub Desktop.
Bike indicators for Micro:bit
This file contains hidden or 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
input.onButtonPressed(Button.A, () => { | |
radio.sendNumber(0) | |
for (let i = 0; i < 10; i++) { | |
basic.showLeds(` | |
. . # . . | |
. # . . . | |
# # # # # | |
. # . . . | |
. . # . . | |
`) | |
basic.clearScreen() | |
basic.pause(100) | |
} | |
}) | |
input.onButtonPressed(Button.B, () => { | |
radio.sendNumber(1) | |
for (let i = 0; i < 10; i++) { | |
basic.showLeds(` | |
. . # . . | |
. . . # . | |
# # # # # | |
. . . # . | |
. . # . . | |
`) | |
basic.clearScreen() | |
basic.pause(100) | |
} | |
}) | |
let direction = 0 | |
radio.onDataPacketReceived(({receivedNumber}) => { | |
direction = receivedNumber | |
if (direction == 1) { | |
basic.clearScreen() | |
for (let i = 0; i < 10; i++) { | |
basic.showLeds(` | |
. . # . . | |
. . . # . | |
# # # # # | |
. . . # . | |
. . # . . | |
`) | |
basic.clearScreen() | |
basic.pause(100) | |
} | |
} | |
if (direction == 0) { | |
basic.clearScreen() | |
for (let i = 0; i < 10; i++) { | |
basic.showLeds(` | |
. . # . . | |
. # . . . | |
# # # # # | |
. # . . . | |
. . # . . | |
`) | |
basic.clearScreen() | |
basic.pause(100) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Utilises two micro bits with the same code as above. Each bit tells each other which arrow to display when you push the corresponding button.