Skip to content

Commit

Permalink
python: update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed May 18, 2024
1 parent 3d4b4df commit f0d15a6
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 72 deletions.
2 changes: 1 addition & 1 deletion python/src/browse-all-music.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def browse_right(index: int) -> int:
display.scroll(song)
Music.play(getattr(Music, song))

sleep(1000)
sleep(1_000)
2 changes: 1 addition & 1 deletion python/src/browse-all-sounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def browse_right(index: int) -> int:
display.scroll(sound)
audio.play(getattr(Sound, sound))

sleep(1000)
sleep(1_000)
2 changes: 1 addition & 1 deletion python/src/browse-all-symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def browse_right(index: int) -> int:
display.scroll(image)
display.show(getattr(Image, image))

sleep(1000)
sleep(1_000)
2 changes: 1 addition & 1 deletion python/src/compass-fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@
print("INFO: NORTH WEST is between 292°-270°, 270°-248°")
display.show(Image.ARROW_NW)

sleep(1000)
sleep(1_000)
2 changes: 1 addition & 1 deletion python/src/compass-real.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,4 @@ def east_arrow(bearing: str) -> None:
print("INFO: NORTH WEST is between 292°-270°, 270°-248°")
draw_arrows("north-west")

sleep(1000)
sleep(1_000)
12 changes: 4 additions & 8 deletions python/src/data-logger.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
# Imports go at the top
from microbit import *
import log
from microbit import *

print("INFO: spining wheel while we log data")
print("INFO: data is in MY_DATA.HTM file")
print("INFO: ok, the interactive log file is pretty cool")

log.set_labels('temperature', 'sound', 'light')
log.set_labels("temperature", "sound", "light")

print("INFO: mirroring log to console")
log.set_mirroring(True)


@run_every(s=5)
def log_data():
log.add({
'temperature': temperature(),
'sound': microphone.sound_level(),
'light': display.read_light_level()
})
log.add({"temperature": temperature(), "sound": microphone.sound_level(), "light": display.read_light_level()})


while True:
display.show(Image.ALL_CLOCKS)
sleep(1000)
sleep(1_000)
2 changes: 1 addition & 1 deletion python/src/entropy-meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
print("INFO: dot=" + str(dot))
display.set_pixel(*dot)

sleep(1000)
sleep(1_000)
4 changes: 2 additions & 2 deletions python/src/game-of-life.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ def evolve(self) -> None:

life.redraw()

sleep(1000)
sleep(1_000)

life.evolve()

if life.alive <= 1:
display.show(Image.NO)
sleep(2000)
sleep(2_000)
life.setup()
4 changes: 2 additions & 2 deletions python/src/hello-world.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
# not the creepy giggle I was hopeing for
print("INFO: Gigggle")
audio.play(Sound.GIGGLE)
sleep(1000)
sleep(1_000)
print("INFO: HELLO")
# closer to the sound "hello"
audio.play(Sound.HELLO)
sleep(1000)
sleep(1_000)
5 changes: 2 additions & 3 deletions python/src/pet-the-microbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
print("INFO: sad")
display.show(Image.SAD)
audio.play(Sound.SAD)
sleep(1000)
sleep(1_000)
else:
print("INFO: angry")
display.show(Image.ANGRY)
# this sounds more like a bird call
audio.play(Sound.YAWN)
sleep(1000)

sleep(1_000)
9 changes: 4 additions & 5 deletions python/src/play-all-sounds.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Imports go at the top
from microbit import *


# Code in a 'while True:' loop repeats forever
while True:
for sound in dir(Sound):
if sound.isupper():
print("sound: " + sound)
audio.play(getattr(Sound, sound))
sleep(1000)
if sound.isupper():
print("sound: " + sound)
audio.play(getattr(Sound, sound))
sleep(1_000)
10 changes: 5 additions & 5 deletions python/src/pomodoro-timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _run_timer(self, name: str, duration: int) -> bool:
display.show(Image.ARROW_W)

while not button_a.was_pressed():
sleep(1000)
sleep(1_000)

reset_button_states()

Expand Down Expand Up @@ -133,7 +133,7 @@ def start_timer(self) -> None:
print("INFO: work timer completed")
display.show(Image.HAPPY)
play_sound_warning("HAPPY")
sleep(1000)
sleep(1_000)

print("==============================")

Expand All @@ -147,7 +147,7 @@ def start_timer(self) -> None:
print("INFO: break timer completed")
display.show(Image.FABULOUS)
play_sound_warning("HAPPY")
sleep(1000)
sleep(1_000)
else:
self._log_data()
print("INFO: break timer canceled")
Expand Down Expand Up @@ -196,7 +196,7 @@ def wait_for_pin_logo(log_mode_enabled: bool, selected: int, durations: "list[tu
display.show(Image.ARROW_E)
sleep(500)

# sleep(1000)
# sleep(1_000)
# display.show(Image.ALL_ARROWS)

if button_a.was_pressed():
Expand Down Expand Up @@ -236,7 +236,7 @@ def wait_for_pin_logo(log_mode_enabled: bool, selected: int, durations: "list[tu
while True:
print("INFO: selected timer -> " + str(durations[selected]))
display.scroll(str(durations[selected]))
sleep(1000)
sleep(1_000)

selected, log_mode_enabled = wait_for_pin_logo(log_mode_enabled, selected, durations)

Expand Down
4 changes: 2 additions & 2 deletions python/src/press-a-button.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
if button_a.was_pressed():
print("INFO: user pressed button A")
display.show(Image.ARROW_W)
sleep(5000)
sleep(5_000)
elif button_b.was_pressed():
print("INFO: user pressed button B")
display.show(Image.ARROW_E)
sleep(5000)
sleep(5_000)
else:
print("INFO: waiting on input")
display.show(Image.ALL_ARROWS)
2 changes: 1 addition & 1 deletion python/src/random-pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ def turn_counter_clockwise(heading: int) -> int:
print("INFO: NORTH WEST is between 292°-270°, 270°-248°")
display.show(Image.ARROW_NW)

sleep(2000)
sleep(2_000)

heading = random.randint(DEGREES_N, DEGREES_N_ALT)
44 changes: 34 additions & 10 deletions python/src/random-timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,37 @@


class MyImages:
hourglass_start: Image = Image("99999:" "09990:" "00900:" "09090:" "90009:")

hourglass_end: Image = Image("90009:" "09090:" "00900:" "09990:" "99999:")

hourglass_progress_0: Image = Image("99999:" "09990:" "00900:" "09690:" "90009:")

hourglass_progress_1: Image = Image("99999:" "09990:" "00900:" "09090:" "90609:")
hourglass_start: Image = Image(
"99999:"
"09990:"
"00900:"
"09090:"
"90009:"
) # fmt: off

hourglass_end: Image = Image(
"90009:"
"09090:"
"00900:"
"09990:"
"99999:"
) # fmt: off

hourglass_progress_0: Image = Image(
"99999:"
"09990:"
"00900:"
"09690:"
"90009:"
) # fmt: off

hourglass_progress_1: Image = Image(
"99999:"
"09990:"
"00900:"
"09090:"
"90609:"
) # fmt: off


myimages = MyImages()
Expand All @@ -22,13 +46,13 @@ class MyImages:
while True:
seconds: int = random.randint(10, 90)
display.show(myimages.hourglass_start)
sleep(1000)
sleep(1_000)

print("INFO: starting " + str(seconds) + " second timer")
for i in range(0, seconds):
display.show(getattr(myimages, "hourglass_progress_" + str(i % 2)))
sleep(1000)
sleep(1_000)

print("INFO: timer has completed")
display.show(myimages.hourglass_end)
sleep(1000)
sleep(1_000)
19 changes: 11 additions & 8 deletions python/src/shake-logger.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# Imports go at the top
from microbit import *
import log
from microbit import *

print("INFO: spining wheel while we log data")
print("INFO: data is in MY_DATA.HTM file")
print("INFO: ok, the interactive log file is pretty cool")

log.set_labels('x', 'y', 'z')
log.set_labels("x", "y", "z")

print("INFO: mirroring log to console")
log.set_mirroring(True)

print("INFO: shake the microbit")


@run_every(s=1)
def log_data():
log.add({
'x': accelerometer.get_x(),
'y': accelerometer.get_y(),
'z': accelerometer.get_z(),
})
log.add(
{
"x": accelerometer.get_x(),
"y": accelerometer.get_y(),
"z": accelerometer.get_z(),
}
)


while True:
display.show(Image.ALL_CLOCKS)
sleep(1000)
sleep(1_000)
9 changes: 4 additions & 5 deletions python/src/show-all-symbols.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Imports go at the top
from microbit import *


# Code in a 'while True:' loop repeats forever
while True:
for image in dir(Image):
if image.isupper():
print("image: " + image)
display.show(getattr(Image, image))
sleep(5000)
if image.isupper():
print("image: " + image)
display.show(getattr(Image, image))
sleep(5_000)
1 change: 0 additions & 1 deletion python/src/sound-meter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Imports go at the top
from microbit import *


# Code in a 'while True:' loop repeats forever
while True:
sound_level: int = microphone.sound_level()
Expand Down
2 changes: 1 addition & 1 deletion python/src/spin-the-wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ def turn_counterclockwise(heading: int) -> int:
print("INFO: NORTH WEST is between 292°-270°, 270°-248°")
display.show(Image.ARROW_NW)

sleep(1000)
sleep(1_000)
3 changes: 1 addition & 2 deletions python/src/temperature-meter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Imports go at the top
from microbit import *


# Code in a 'while True:' loop repeats forever
while True:
# not very sensitive, well lit room registers at 0
# using cell phone flash light near it get at least 100 score
temp_c: int = temperature()
temp_f: int = round(temp_c * (9/5)) + 32
temp_f: int = round(temp_c * (9 / 5)) + 32

print("INFO: the ambient temperature is " + str(temp_c) + "°C")
print("INFO: the ambient temperature is " + str(temp_f) + "°F")
Expand Down
Loading

0 comments on commit f0d15a6

Please sign in to comment.