Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
talit:microbit [2024-04-21 19:23] – [Auftrag 3] sca | talit:microbit [2024-04-29 11:36] (aktuell) – [Lösungen Aufgaben] sca | ||
---|---|---|---|
Zeile 35: | Zeile 35: | ||
- | ===== - Micro:bit kennenlernen | + | ===== - Aufgaben |
Die hilfreichste Quelle ist das Wiki vom Grundlagenfach 2M: https:// | Die hilfreichste Quelle ist das Wiki vom Grundlagenfach 2M: https:// | ||
- | ==== Auftrag | + | ==== Aufgabe |
+ | |||
+ | Erstelle GitHub-Repo **microbit**, | ||
1. Das LED im Zentrum der $5 \times 5-$LED-Matrix soll leuchten. Drückt man den linken/ | 1. Das LED im Zentrum der $5 \times 5-$LED-Matrix soll leuchten. Drückt man den linken/ | ||
Zeile 49: | Zeile 51: | ||
1. Wahrscheinlich gibt es jetzt eine Fehlermeldung, | 1. Wahrscheinlich gibt es jetzt eine Fehlermeldung, | ||
- | ==== Auftrag | + | ==== Aufgabe |
Implementiere einen Würfel. Drückt man eine der beiden Tasten, soll eine Zufallszahl $1$ bis $6$ generiert (-> random-Modul) und das entsprechende Würfelsymbol angezeigt werden. Zeichne die Bilder mit `display.set_pixel(...)` selbst. | Implementiere einen Würfel. Drückt man eine der beiden Tasten, soll eine Zufallszahl $1$ bis $6$ generiert (-> random-Modul) und das entsprechende Würfelsymbol angezeigt werden. Zeichne die Bilder mit `display.set_pixel(...)` selbst. | ||
- | ==== Auftrag | + | ==== Aufgabe |
1. Fotoschau: Im micro:bit sind viele verschiedene Bilder vordefiniert. Speichere einige davon in einer Liste. Mit den beiden Knöpfen soll man die Bilder durchgehen können. | 1. Fotoschau: Im micro:bit sind viele verschiedene Bilder vordefiniert. Speichere einige davon in einer Liste. Mit den beiden Knöpfen soll man die Bilder durchgehen können. | ||
Zeile 61: | Zeile 63: | ||
Optional: | Optional: | ||
- | 1. Über BLE können mehrere micro:bit miteinander kommunizieren. Verbinde zwei micro:bit miteinander und modifiziere den Würfel-Code wie folgt: Auf beiden micro:bits wird immer der gleiche Würfel angezeigt. Drückt man auf einem der beiden micro:bits einen Knopf, wird eine neue Zahl gewürfelt und auf *beiden* angezeigt. | + | |
- | ==== Lösungen ==== | + | ==== Lösungen |
+ | |||
+ | |||
+ | ++++Lösungen| | ||
<nodisp 2> | <nodisp 2> | ||
Zeile 93: | Zeile 98: | ||
def dice(n): | def dice(n): | ||
display.clear() | display.clear() | ||
- | if n % 2 == 1: | + | if n == 1: |
display.set_pixel(2, | display.set_pixel(2, | ||
- | | + | |
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | elif n == 3: | ||
+ | display.set_pixel(2, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | elif n == 4: | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | elif n == 5: | ||
+ | display.set_pixel(2, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | elif n == 6: | ||
display.set_pixel(0, | display.set_pixel(0, | ||
display.set_pixel(4, | display.set_pixel(4, | ||
- | if n >= 4: | ||
display.set_pixel(0, | display.set_pixel(0, | ||
display.set_pixel(4, | display.set_pixel(4, | ||
- | if n == 6: | ||
display.set_pixel(0, | display.set_pixel(0, | ||
display.set_pixel(4, | display.set_pixel(4, | ||
Zeile 109: | Zeile 130: | ||
dice(random.randint(1, | dice(random.randint(1, | ||
sleep(100) | sleep(100) | ||
+ | </ | ||
+ | |||
+ | Alternative Ideen für dice-Funktion: | ||
+ | |||
+ | <code python> | ||
+ | |||
+ | ### Variante 1 | ||
+ | |||
+ | def dice(n): | ||
+ | display.clear() | ||
+ | if n == 1: | ||
+ | display.set_pixel(2, | ||
+ | elif n == 2: | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | elif n == 3: | ||
+ | display.set_pixel(2, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | elif n == 4: | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | elif n == 5: | ||
+ | display.set_pixel(2, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | elif n == 6: | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | |||
+ | ### Variante 2 | ||
+ | def dice(n): | ||
+ | dots = [ | ||
+ | [[2,2]], | ||
+ | [[0, | ||
+ | [[2, | ||
+ | [[0, | ||
+ | [[2, | ||
+ | [[0, | ||
+ | ] | ||
+ | display.clear() | ||
+ | for pixel in dots[n-1]: | ||
+ | display.set_pixel(pixel[0], | ||
+ | |||
+ | ### Variante 3 | ||
+ | |||
+ | def dice(n): | ||
+ | display.clear() | ||
+ | if n % 2 == 1: | ||
+ | display.set_pixel(2, | ||
+ | if n >= 2: | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | if n >= 4: | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
+ | if n == 6: | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(4, | ||
</ | </ | ||
<code python auftrag_3.py> | <code python auftrag_3.py> | ||
- | asd | ||
</ | </ | ||
+ | |||
</ | </ | ||
+ | ++++ | ||