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_sca [2023-06-28 03:15] – [Aufgaben E (Radio – Nachrichten über BLE senden)] sca | gf_informatik:microbit_sca [2023-06-28 03:40] (aktuell) – [Aufgabe E6 (Anonyme Umfragen)] sca | ||
|---|---|---|---|
| Zeile 175: | Zeile 175: | ||
| ===== - Aufgaben D (Sounds) ===== | ===== - Aufgaben D (Sounds) ===== | ||
| + | |||
| + | **Relevante Theorie:** | ||
| + | |||
| + | * [[gf_informatik: | ||
| + | |||
| + | |||
| === Aufgabe D1 === | === Aufgabe D1 === | ||
| Schreibe ein Programm, dass die Melodie //Frère Jacques// spielt (mit Pause zwischen gleichen Tönen), **solange du die A-Taste gedrückt hältst**: | Schreibe ein Programm, dass die Melodie //Frère Jacques// spielt (mit Pause zwischen gleichen Tönen), **solange du die A-Taste gedrückt hältst**: | ||
| Zeile 251: | Zeile 257: | ||
| * Mit der B-Taste soll neben dem Tempo auch die Tonlage verringert werden. | * Mit der B-Taste soll neben dem Tempo auch die Tonlage verringert werden. | ||
| - | === Lösungen === | ||
| - | <nodisp 2> | ||
| - | ++++Lösungen Aufgaben D| | ||
| - | === D1 === | ||
| - | <code python> | ||
| - | from microbit import* | ||
| - | import music | ||
| - | # Frère Jacques: | + | ===== - Aufgaben E (Radio) ===== |
| - | melody_jacques | + | |
| - | ' | + | |
| - | ' | + | |
| - | ' | + | |
| - | ' | + | |
| - | note = 0 | + | **Relevante Theorie:** |
| - | while True: | + | |
| - | if(button_a.is_pressed()): | + | |
| - | music.play(melody_jacques[note]) | + | |
| - | sleep(30) | + | |
| - | if(note < len(melody_jacques)-1): | + | |
| - | note += 1 | + | |
| - | else: | + | |
| - | note = 0 | + | |
| - | </ | + | |
| - | === D2 === | + | * [[gf_informatik: |
| - | <code python> | + | |
| - | from microbit import* | + | |
| - | import music | + | |
| - | # Frère Jacques: | + | === Aufgabe E1 === |
| - | melody_jacques | + | |
| - | ' | + | |
| - | ' | + | |
| - | ' | + | |
| - | ' | + | |
| - | + | ||
| - | note = 0 | + | |
| - | while True: | + | |
| - | if(button_a.is_pressed()): | + | |
| - | display.show(Image.HAPPY) | + | |
| - | music.play(melody_jacques[note]) | + | |
| - | sleep(30) | + | |
| - | if(note < len(melody_jacques)-1): | + | |
| - | note += 1 | + | |
| - | else: | + | |
| - | note = 0 | + | |
| - | else: | + | |
| - | display.show(Image.ARROW_W) | + | |
| - | </ | + | |
| - | + | ||
| - | === D3 === | + | |
| - | <code python> | + | |
| - | from microbit import* | + | |
| - | import music | + | |
| - | + | ||
| - | # Frère Jacques: | + | |
| - | melody_jacques = [' | + | |
| - | ' | + | |
| - | ' | + | |
| - | ' | + | |
| - | ' | + | |
| - | + | ||
| - | # Popcorn: | + | |
| - | melody_pop = | + | |
| - | ' | + | |
| - | ' | + | |
| - | ' | + | |
| - | + | ||
| - | noteA = 0 | + | |
| - | noteB = 0 | + | |
| - | while True: | + | |
| - | if(button_a.is_pressed()): | + | |
| - | music.set_tempo(bpm = 120) # Diese Melodie normal spielen | + | |
| - | display.show(Image.ASLEEP) | + | |
| - | music.play(melody_jacques[noteA]) | + | |
| - | sleep(30) | + | |
| - | if(noteA < len(melody_jacques)-1): | + | |
| - | noteA += 1 | + | |
| - | else: | + | |
| - | noteA = 0 | + | |
| - | elif(button_b.is_pressed()): | + | 1. Schreibe ein Programm zum Nachrichtenaustausch: Mit beiden Tasten und dem Touch-Logo |
| - | music.set_tempo(bpm = 200) # Diese Melodie schneller spielen | + | 1. Weiter soll der Micro:Bit diese drei Nachrichten empfangen und anzeigen können: Wird ' |
| - | display.show(Image.MUSIC_CROTCHET) | + | 1. Einige dich mit deiner Kolleg:in auf eine eigene Gruppe oder Kanal, |
| - | music.play(melody_pop[noteB]) | + | |
| - | sleep(30) | + | |
| - | if(noteB < len(melody_pop)-1): | + | |
| - | noteB += 1 | + | |
| - | else: | + | |
| - | noteB = 0 | + | |
| - | + | ||
| - | else: | + | |
| - | display.clear() | + | |
| - | </ | + | |
| - | + | ||
| - | === D4 === | + | |
| - | <code python> | + | |
| - | from microbit import * | + | |
| - | import music | + | |
| - | + | ||
| - | while True: | + | |
| - | for freq in range(330, 770, 10): | + | |
| - | music.pitch(freq, | + | |
| - | for freq in range(770, 330, -10): | + | |
| - | music.pitch(freq, | + | |
| - | </ | + | |
| - | + | ||
| - | === D5 === | + | |
| - | <code python> | + | |
| - | from microbit import * | + | |
| - | import music | + | |
| - | + | ||
| - | freq = 440 # A4 | + | |
| - | while True: | + | |
| - | if button_a.is_pressed(): | + | |
| - | if freq < 4000: | + | |
| - | freq += 100 | + | |
| - | music.pitch(freq, | + | |
| - | if button_b.is_pressed(): | + | |
| - | if freq > 100: | + | |
| - | freq -= 100 | + | |
| - | music.pitch(freq, | + | |
| - | </ | + | |
| - | + | ||
| - | === D6 === | + | |
| - | <code python> | + | |
| - | from microbit import * | + | |
| - | import music | + | |
| - | + | ||
| - | while True: | + | |
| - | if accelerometer.was_gesture(" | + | |
| - | display.show(Image.HAPPY) | + | |
| - | music.play(music.JUMP_UP) | + | |
| - | elif accelerometer.was_gesture(" | + | |
| - | display.show(Image.SAD) | + | |
| - | music.play(music.JUMP_DOWN) | + | |
| - | else: | + | |
| - | display.clear() | + | |
| - | </ | + | |
| - | ++++ | + | |
| - | </ | + | |
| - | + | ||
| - | + | ||
| - | ===== - Aufgaben E (BLE) ===== | + | |
| - | + | ||
| - | === Aufgabe E1 === | + | |
| - | Erweitert euer Programm zum Nachrichtenaustausch | + | |
| === Aufgabe E2 === | === Aufgabe E2 === | ||
| Zeile 410: | Zeile 279: | ||
| * Solange eine Nachricht empfangen wird, soll das gesamte Display hell leuchten. | * Solange eine Nachricht empfangen wird, soll das gesamte Display hell leuchten. | ||
| * Solange keine Nachricht empfangen wird, soll das Display nicht leuchten. | * Solange keine Nachricht empfangen wird, soll das Display nicht leuchten. | ||
| + | |||
| + | {{: | ||
| === Aufgabe E4 (Beacon 1) === | === Aufgabe E4 (Beacon 1) === | ||
| Zeile 441: | Zeile 312: | ||
| Schreibt ein Programm, mit dem ihr anonyme Umfragen durchführen könnt. | Schreibt ein Programm, mit dem ihr anonyme Umfragen durchführen könnt. | ||
| - | * Wenn die Taste A gedrückt wird, sendet der Microbit die Nachricht "jo". | + | * Wenn die Taste A gedrückt wird, sendet der Microbit die Nachricht "Ja". |
| - | * Wenn die Taste B gedrückt wird, sendet der Microbit die Nachricht "nai". | + | * Wenn die Taste B gedrückt wird, sendet der Microbit die Nachricht "Nein". |
| - | * Füge für beide Tasten eine Verzögerung mit '' | + | * Verwende `get_presses()` und füge zur Sicherheit den Tasten eine Verzögerung mit '' |
| * Wann immer eine Nachricht empfangen wird, wird sie ausgewertet: | * Wann immer eine Nachricht empfangen wird, wird sie ausgewertet: | ||
| - | * Ist der Inhalt der Nachricht "jo", so wird eine Variable zum Zählen der Ja-Stimmen um 1 erhöht. | + | * Ist der Inhalt der Nachricht "Ja", so wird eine Variable zum Zählen der Ja-Stimmen um 1 erhöht. |
| - | * Ist der Inhalt der Nachricht "nai", so wird eine Variable zum Zählen der Nein-Stimmen um 1 erhöht. | + | * Ist der Inhalt der Nachricht "Nein", so wird eine Variable zum Zählen der Nein-Stimmen um 1 erhöht. |
| - | * Wenn das Touch-Logo berührt wird, soll das Display die Anzahl Ja- und die Anzahl Nein-Stimmen anzeigen | + | * Wenn das Touch-Logo berührt wird, soll das Display die Anzahl Ja- und die Anzahl Nein-Stimmen anzeigen. |
| * Testet euer Programm: Einigt euch zu viert auf dieselbe Gruppen-Nummer (oder Kanal-Nummer), | * Testet euer Programm: Einigt euch zu viert auf dieselbe Gruppen-Nummer (oder Kanal-Nummer), | ||
| Zeile 795: | Zeile 666: | ||
| ++++ | ++++ | ||
| </ | </ | ||
| + | |||
| + | <nodisp 2> | ||
| + | ++++Lösungen Aufgaben D| | ||
| + | === D1 === | ||
| + | <code python> | ||
| + | from microbit import* | ||
| + | import music | ||
| + | |||
| + | # Frère Jacques: | ||
| + | melody_jacques = [' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | |||
| + | note = 0 | ||
| + | while True: | ||
| + | if(button_a.is_pressed()): | ||
| + | music.play(melody_jacques[note]) | ||
| + | sleep(30) | ||
| + | if(note < len(melody_jacques)-1): | ||
| + | note += 1 | ||
| + | else: | ||
| + | note = 0 | ||
| + | </ | ||
| + | |||
| + | === D2 === | ||
| + | <code python> | ||
| + | from microbit import* | ||
| + | import music | ||
| + | |||
| + | # Frère Jacques: | ||
| + | melody_jacques = [' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | |||
| + | note = 0 | ||
| + | while True: | ||
| + | if(button_a.is_pressed()): | ||
| + | display.show(Image.HAPPY) | ||
| + | music.play(melody_jacques[note]) | ||
| + | sleep(30) | ||
| + | if(note < len(melody_jacques)-1): | ||
| + | note += 1 | ||
| + | else: | ||
| + | note = 0 | ||
| + | else: | ||
| + | display.show(Image.ARROW_W) | ||
| + | </ | ||
| + | |||
| + | === D3 === | ||
| + | <code python> | ||
| + | from microbit import* | ||
| + | import music | ||
| + | |||
| + | # Frère Jacques: | ||
| + | melody_jacques = [' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | |||
| + | # Popcorn: | ||
| + | melody_pop = | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | |||
| + | noteA = 0 | ||
| + | noteB = 0 | ||
| + | while True: | ||
| + | if(button_a.is_pressed()): | ||
| + | music.set_tempo(bpm = 120) # Diese Melodie normal spielen | ||
| + | display.show(Image.ASLEEP) | ||
| + | music.play(melody_jacques[noteA]) | ||
| + | sleep(30) | ||
| + | if(noteA < len(melody_jacques)-1): | ||
| + | noteA += 1 | ||
| + | else: | ||
| + | noteA = 0 | ||
| + | |||
| + | elif(button_b.is_pressed()): | ||
| + | music.set_tempo(bpm = 200) # Diese Melodie schneller spielen | ||
| + | display.show(Image.MUSIC_CROTCHET) | ||
| + | music.play(melody_pop[noteB]) | ||
| + | sleep(30) | ||
| + | if(noteB < len(melody_pop)-1): | ||
| + | noteB += 1 | ||
| + | else: | ||
| + | noteB = 0 | ||
| + | |||
| + | else: | ||
| + | display.clear() | ||
| + | </ | ||
| + | |||
| + | === D4 === | ||
| + | <code python> | ||
| + | from microbit import * | ||
| + | import music | ||
| + | |||
| + | while True: | ||
| + | for freq in range(330, 770, 10): | ||
| + | music.pitch(freq, | ||
| + | for freq in range(770, 330, -10): | ||
| + | music.pitch(freq, | ||
| + | </ | ||
| + | |||
| + | === D5 === | ||
| + | <code python> | ||
| + | from microbit import * | ||
| + | import music | ||
| + | |||
| + | freq = 440 # A4 | ||
| + | while True: | ||
| + | if button_a.is_pressed(): | ||
| + | if freq < 4000: | ||
| + | freq += 100 | ||
| + | music.pitch(freq, | ||
| + | if button_b.is_pressed(): | ||
| + | if freq > 100: | ||
| + | freq -= 100 | ||
| + | music.pitch(freq, | ||
| + | </ | ||
| + | |||
| + | === D6 === | ||
| + | <code python> | ||
| + | from microbit import * | ||
| + | import music | ||
| + | |||
| + | while True: | ||
| + | if accelerometer.was_gesture(" | ||
| + | display.show(Image.HAPPY) | ||
| + | music.play(music.JUMP_UP) | ||
| + | elif accelerometer.was_gesture(" | ||
| + | display.show(Image.SAD) | ||
| + | music.play(music.JUMP_DOWN) | ||
| + | else: | ||
| + | display.clear() | ||
| + | </ | ||
| + | ++++ | ||
| + | </ | ||
| + | |||