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:repetitionsaufgaben [2023-09-20 18:09] – [RD2 – Satzgenerator] gra | gf_informatik:microbit_und_roboter_programmieren:repetitionsaufgaben [2023-10-04 14:29] (aktuell) – [Aufgaben RD] gra | ||
---|---|---|---|
Zeile 42: | Zeile 42: | ||
===== RB – Microbit und Funktionen ===== | ===== RB – Microbit und Funktionen ===== | ||
- | In folgenden | + | Für folgende |
=== RB1 – Helligkeit Null bis Neun === | === RB1 – Helligkeit Null bis Neun === | ||
Zeile 85: | Zeile 85: | ||
* Die Binärzahl ist ein String aus den Zeichen `' | * Die Binärzahl ist ein String aus den Zeichen `' | ||
* Deine Funktion '' | * Deine Funktion '' | ||
- | * Wenn du das Touch-Logo drückst, wird zuerst die Binärzahl, dann die ensprechende Dezimalzahl an die Serial-Konsole ausgegeben (mit print). Dann wird die eingegebene Binärzahl gelöscht. | + | * Wenn du das Touch-Logo drückst, wird zuerst die Binärzahl, dann die ensprechende Dezimalzahl an die Serial-Konsole ausgegeben (mit '' |
+ | |||
+ | === RC4 – Rauf und runter === | ||
+ | Schreibe Code der abwechslungsweise eine fallende und eine steigende Diagnoale zeichnet: | ||
+ | * Erst bewegt sich das Pixel von unten links nach oben rechts und zieht eine Linie. Dann wird das Display gelöscht. Dann folgt die fallende Linie von links nach rechts. Dann beginnt das Programm von vorne. | ||
+ | * Verwende **zwei for-schleifen** und die Funktion '' | ||
===== RD – Microbit und Listen ===== | ===== RD – Microbit und Listen ===== | ||
Für die folgenden Aufgaben benötigst du (neben Variablen, Verzweigungen, | Für die folgenden Aufgaben benötigst du (neben Variablen, Verzweigungen, | ||
Zeile 101: | Zeile 106: | ||
<code python> | <code python> | ||
subjekte = [" | subjekte = [" | ||
- | verben = [" | + | verben = [" |
- | adjektive = [" | + | adjektive = [" |
objekte = [" | objekte = [" | ||
</ | </ | ||
- | === RD3 – Textnachricht | + | === RD3 – Text schreiben |
+ | Schreibe Code, mit dem Du ein Wort schreiben und an die Serial-Konsole senden kannst: | ||
+ | * Mit der A-Taste kannst du durch die Buchstaben des Alphabets blättern (siehe Liste unten). Nach z kommt wieder a. Das Display zeigt den aktuellen Buchstaben. | ||
+ | * Mit der B-Taste wählst du den aktuellen Buchstaben aus und fügst ihn zum Wort hinzu. | ||
+ | * Wenn du das Touch-Logo berührst, wird das Wort an die Serial-Konsole gesendet und anschliessend gelöscht. | ||
+ | |||
+ | <code python> | ||
+ | buchstaben = [" | ||
+ | </ | ||
+ | |||
+ | ===== Lösungen ===== | ||
+ | |||
+ | === Aufgaben RA === | ||
+ | <nodisp 1> | ||
+ | ++++ RA1:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | |||
+ | zahl1 = 0 | ||
+ | zahl2 = 0 | ||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | zahl1 += 1 | ||
+ | if button_b.was_pressed(): | ||
+ | zahl2 += 1 | ||
+ | if pin_logo.is_touched(): | ||
+ | display.show(zahl1 + zahl2) | ||
+ | sleep(100) | ||
+ | zahl1 = 0 | ||
+ | zahl2 = 0 | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RA2:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | |||
+ | zahl1 = 0 | ||
+ | while True: | ||
+ | if button_a.was_pressed() and zahl1 < 9: | ||
+ | zahl1 += 1 | ||
+ | if button_b.was_pressed() and zahl1 > 0: | ||
+ | zahl1 -= 1 | ||
+ | display.show(zahl1) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RA3:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | |||
+ | zahl1 = 0 | ||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | if zahl1 > 6: | ||
+ | zahl1 = 0 | ||
+ | else: | ||
+ | zahl1 = zahl1 + 1 | ||
+ | |||
+ | display.show(zahl1) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RA4:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import random | ||
+ | |||
+ | zahl1 = 0 | ||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | zahl1 = random.randint(1, | ||
+ | | ||
+ | | ||
+ | if zahl1 % 7 == 0: | ||
+ | | ||
+ | elif zahl1 % 5 == 0: | ||
+ | | ||
+ | elif zahl1 % 3 == 0: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RA5:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import random | ||
+ | |||
+ | temp_c = 0 | ||
+ | while True: | ||
+ | temp_c = temperature() | ||
+ | if button_a.was_pressed(): | ||
+ | print(str(temp_c)+' | ||
+ | if button_b.was_pressed(): | ||
+ | print(str(temp_c *9/5 + 32) + '° F') | ||
+ | if pin_logo.is_touched(): | ||
+ | print(str(temp_c+273.15) + ' | ||
+ | sleep(100) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | </ | ||
+ | === Aufgaben RB === | ||
+ | <nodisp 1> | ||
+ | ++++ RB1:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | |||
+ | def make_heart_image(b): | ||
+ | heart_string = ' | ||
+ | new_string = heart_string.replace(' | ||
+ | return Image(new_string) | ||
+ | |||
+ | helligkeit = 4 | ||
+ | while True: | ||
+ | if button_a.was_pressed() and helligkeit > 0: | ||
+ | helligkeit = helligkeit - 1 | ||
+ | if button_b.was_pressed() and helligkeit < 9: | ||
+ | helligkeit = helligkeit + 1 | ||
+ | display.show(make_heart_image(helligkeit)) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RB2:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | |||
+ | def draw_horizontal_line(y_pos): | ||
+ | display.clear() | ||
+ | display.set_pixel(0, | ||
+ | display.set_pixel(1, | ||
+ | display.set_pixel(2, | ||
+ | display.set_pixel(3, | ||
+ | display.set_pixel(4, | ||
+ | |||
+ | y = 0 | ||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | y = (y + 1) % 5 | ||
+ | draw_horizontal_line(y) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RB3:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | |||
+ | def print_acc_values(u): | ||
+ | if u == 0: | ||
+ | unit_string = " mg" | ||
+ | factor = 1 | ||
+ | elif u == 1: | ||
+ | unit_string = " g" | ||
+ | factor = 0.001 | ||
+ | else: | ||
+ | unit_string = " m/ | ||
+ | factor = 0.00981 | ||
+ | x, y, z = accelerometer.get_values() | ||
+ | print(" | ||
+ | print(" | ||
+ | print(" | ||
+ | |||
+ | unit = 0 | ||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | unit = (unit + 1) % 3 | ||
+ | print_acc_values(unit) | ||
+ | sleep(500) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RB4:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import math | ||
+ | |||
+ | def get_total_acc(): | ||
+ | x, y, z = accelerometer.get_values() | ||
+ | a_tot = math.sqrt(x*x + y*y + z*z) | ||
+ | a_max = 3464 | ||
+ | a = int(a_tot/ | ||
+ | return a | ||
+ | |||
+ | while True: | ||
+ | display.show(get_total_acc()) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | </ | ||
+ | === Aufgaben RC === | ||
+ | <nodisp 1> | ||
+ | ++++ RC1:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import random | ||
+ | |||
+ | while True: | ||
+ | column = random.randint(0, | ||
+ | for row in range(0, | ||
+ | display.set_pixel(column, | ||
+ | sleep(40) | ||
+ | display.clear() | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RC2:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import random | ||
+ | |||
+ | def shoot(a_shoots): | ||
+ | row = random.randint(0, | ||
+ | if a_shoots: | ||
+ | start_column = 0 | ||
+ | stop_column = 5 | ||
+ | step = 1 | ||
+ | else: | ||
+ | start_column = 4 | ||
+ | stop_column = -1 | ||
+ | step = -1 | ||
+ | for column in range(start_column, | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | shoot(True) | ||
+ | if button_b.was_pressed(): | ||
+ | shoot(False) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RC3:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import random | ||
+ | |||
+ | def binary_to_decimal(binary_string): | ||
+ | decimal = 0 | ||
+ | place_value = 1 | ||
+ | for bit in reversed(binary_string): | ||
+ | decimal = decimal + int(bit) * place_value | ||
+ | place_value = place_value * 2 | ||
+ | return decimal | ||
+ | |||
+ | binary = '' | ||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | binary = binary + ' | ||
+ | if button_b.was_pressed(): | ||
+ | binary = binary + ' | ||
+ | if pin_logo.is_touched(): | ||
+ | print(binary) | ||
+ | print(binary_to_decimal(binary)) | ||
+ | sleep(100) | ||
+ | binary = '' | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RC4:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | |||
+ | while True: | ||
+ | for i in range(0, | ||
+ | display.set_pixel(i, | ||
+ | sleep(100) | ||
+ | display.clear() | ||
+ | for i in range(0, | ||
+ | display.set_pixel(i, | ||
+ | sleep(100) | ||
+ | display.clear() | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | </ | ||
+ | === Aufgaben RD === | ||
+ | <nodisp 1> | ||
+ | ++++ RD1:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import random | ||
+ | |||
+ | index = 0 | ||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | index = (index + 1) % 12 | ||
+ | display.show(Image.ALL_CLOCKS[index]) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RD2:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import random | ||
+ | |||
+ | subjekte = [" | ||
+ | verben = [" | ||
+ | adjektive = [" | ||
+ | objekte = [" | ||
+ | |||
+ | index = 0 | ||
+ | while True: | ||
+ | if button_a.was_pressed(): | ||
+ | subjekt = random.choice(subjekte) | ||
+ | verb = random.choice(verben) | ||
+ | adjektiv = random.choice(adjektive) | ||
+ | objekt = random.choice(objekte) | ||
+ | satz = "{} {} {} {}." | ||
+ | print(satz) | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ RD3:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | |||
+ | buchstaben = [" | ||
+ | |||
+ | index = 0 | ||
+ | wort = '' | ||
+ | while True: | ||
+ | display.show(buchstaben[index]) | ||
+ | if button_a.was_pressed(): | ||
+ | index = (index + 1) % 26 | ||
+ | if button_b.was_pressed(): | ||
+ | wort = wort + buchstaben[index] | ||
+ | if pin_logo.is_touched(): | ||
+ | print(wort) | ||
+ | sleep(100) | ||
+ | wort = '' | ||
+ | </ | ||
+ | ++++ | ||
- | === RD4 – Spirale? === | ||
+ | </ |