Created
January 31, 2017 23:43
-
-
Save oschettler/c14aa3c7af3666aacffce028b9e4f7ec 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
from microbit import * | |
import music | |
def display_digit(x, digit): | |
"Show a single digit in column" | |
x = 4 - x | |
digit = 9 - digit | |
for j in range(5): | |
y = digit - j | |
if y >= 0 and y < 5: | |
display.set_pixel(x, y, 9) | |
def display_number_at(x, number): | |
"Show a two-digit number at given column" | |
for i in range(2): | |
tenth = number // 10 | |
digit = number - tenth * 10 | |
number = tenth | |
display_digit(x + i, digit) | |
def display_numbers(number1, number2): | |
"Show two two-digit numbers on the LED matrix" | |
display.clear() | |
display_number_at(3, number1) | |
display_number_at(0, number2) | |
def count_down(minutes, dot): | |
minutes = minutes - 1 | |
seconds = 60 | |
while minutes > 0 or seconds > 0: | |
if button_a.was_pressed(): | |
display.clear() | |
return | |
sleep(900) | |
if dot: | |
display.set_pixel(2, 0, 5) | |
sleep(100) | |
seconds = seconds - 1 | |
display_numbers(minutes, seconds) | |
if minutes == 0 and seconds < 10: | |
music.pitch(440, 10) | |
if seconds == 0 and minutes > 0: | |
minutes = minutes - 1 | |
seconds = 60 | |
music.play(music.POWER_UP) | |
while True: | |
if button_a.was_pressed(): | |
work_minutes = button_b.get_presses() | |
if work_minutes == 0: | |
work_minutes = 20 | |
pause_minutes = work_minutes // 4 | |
music.play(["C4:2", "G4:2"]) | |
count_down(work_minutes, True) | |
music.play(["G4:2", "C4:2"]) | |
if pause_minutes > 0: | |
count_down(pause_minutes, False) | |
music.play(["C4:2", "G4:2"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment