Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
gf_informatik:microbit_und_roboter_programmieren:aufgaben_hof [2024-09-20 07:25] – hof | gf_informatik:microbit_und_roboter_programmieren:aufgaben_hof [2025-09-23 12:14] (aktuell) – hof | ||
---|---|---|---|
Zeile 262: | Zeile 262: | ||
Tipps: | Tipps: | ||
* Definiere zuerst Bilder für die sechs Seiten des Würfels. | * Definiere zuerst Bilder für die sechs Seiten des Würfels. | ||
- | * Verwende das '' | + | * Verwende das '' |
{{ : | {{ : | ||
Zeile 512: | Zeile 512: | ||
<code python> | <code python> | ||
from microbit import * | from microbit import * | ||
+ | |||
while True: | while True: | ||
- | # Sound level from 0..250 | + | # Sound level from 0..255 |
level = microphone.sound_level() | level = microphone.sound_level() | ||
- | # How many leds do we light up? | + | # How bright |
- | | + | |
- | # How bright ist the last led? | + | |
- | brightness = level % 10 | + | |
for x in range(5): | for x in range(5): | ||
for y in range(5): | for y in range(5): | ||
- | | + | display.set_pixel(x, |
- | if value < leds: | + | |
- | display.set_pixel(x, | + | |
- | elif value == leds: | + | |
- | | + | |
- | else: | + | |
- | display.set_pixel(x, | + | |
sleep(10) | sleep(10) | ||
</ | </ | ||
Zeile 550: | Zeile 542: | ||
for y in range(5): | for y in range(5): | ||
if x < 4: | if x < 4: | ||
+ | # Copy value from next column, such that the columns | ||
+ | # scroll from right to left side of display. | ||
display.set_pixel(x, | display.set_pixel(x, | ||
elif 4-y < leds: | elif 4-y < leds: | ||
+ | # In the rightmost column, draw the bar for the current | ||
+ | # volume. | ||
display.set_pixel(x, | display.set_pixel(x, | ||
elif 4-y == leds: | elif 4-y == leds: | ||
+ | # Top non-dark pixel of the bar is dimmed according to fractional | ||
+ | # volume. | ||
display.set_pixel(x, | display.set_pixel(x, | ||
else: | else: | ||
+ | # The top pixels of the last column are black (cleared) | ||
display.set_pixel(x, | display.set_pixel(x, | ||
Zeile 895: | Zeile 894: | ||
* Button B: fährt nach rechts (wenn Touch Logo gleichzeitig gedrückt) | * Button B: fährt nach rechts (wenn Touch Logo gleichzeitig gedrückt) | ||
- | < | + | < |
++++Lösungen| | ++++Lösungen| | ||
=== G1 === | === G1 === | ||
Zeile 927: | Zeile 926: | ||
chassis.stop() | chassis.stop() | ||
</ | </ | ||
+ | ++++ | ||
+ | </ | ||
+ | <nodisp 2> | ||
+ | ++++Lösungen| | ||
=== G3 === | === G3 === |