Created
May 4, 2020 08:08
-
-
Save cyberparra/f4c1a94cb95885c6ddd4b3cf1e663513 to your computer and use it in GitHub Desktop.
Microbit clock
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
let clockmode = 0 | |
let min = 0 | |
let hour = 0 | |
input.onButtonPressed(Button.B, function () { | |
clockmode = 0 | |
min += 1 | |
if (min == 60) { | |
min = 0 | |
} | |
basic.showNumber(min) | |
basic.pause(2000) | |
basic.clearScreen() | |
}) | |
input.onButtonPressed(Button.AB, function () { | |
clockmode = 1 | |
}) | |
input.onButtonPressed(Button.A, function () { | |
clockmode = 0 | |
hour += 1 | |
if (hour == 24) { | |
hour = 0 | |
} | |
basic.showNumber(hour) | |
basic.pause(2000) | |
basic.clearScreen() | |
}) | |
basic.forever(function () { | |
if (clockmode == 1) { | |
basic.showNumber(hour) | |
basic.pause(200) | |
basic.clearScreen() | |
basic.showNumber(min) | |
basic.pause(200) | |
basic.clearScreen() | |
basic.pause(500) | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. # # # . | |
. . . . . | |
. . . . . | |
`) | |
basic.pause(500) | |
basic.clearScreen() | |
} | |
}) | |
basic.forever(function () { | |
if (clockmode == 1) { | |
basic.pause(60000) | |
min += 1 | |
if (min == 60) { | |
min = 0 | |
hour += 1 | |
if (hour == 24) { | |
hour = 0 | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment