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-27 05:07] – [RD3 – Text schreiben und senden] gra | gf_informatik:microbit_und_roboter_programmieren:repetitionsaufgaben [2023-10-04 14:29] (aktuell) – [Aufgaben RD] gra | ||
---|---|---|---|
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 === | === RC4 – Rauf und runter === | ||
Zeile 122: | Zeile 122: | ||
===== Lösungen ===== | ===== Lösungen ===== | ||
- | === Aufgaben RA === | ||
+ | === Aufgaben RA === | ||
+ | <nodisp 1> | ||
++++ RA1:| | ++++ RA1:| | ||
<code python> | <code python> | ||
Zeile 137: | Zeile 138: | ||
if pin_logo.is_touched(): | if pin_logo.is_touched(): | ||
display.show(zahl1 + zahl2) | display.show(zahl1 + zahl2) | ||
- | sleep(1000) | + | sleep(100) |
zahl1 = 0 | zahl1 = 0 | ||
zahl2 = 0 | zahl2 = 0 | ||
Zeile 143: | Zeile 144: | ||
++++ | ++++ | ||
+ | ++++ 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: | ||
+ | | ||
+ | else: | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ 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 === | === 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/ss" | ||
+ | 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 === | === Aufgaben RC === | ||
+ | <nodisp 1> | ||
+ | ++++ RC1:| | ||
+ | <code python> | ||
+ | from microbit import * | ||
+ | import random | ||
+ | |||
+ | while True: | ||
+ | column = random.randint(0, | ||
+ | for row in range(0,5): | ||
+ | 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,5): | ||
+ | display.set_pixel(i, | ||
+ | sleep(100) | ||
+ | display.clear() | ||
+ | for i in range(0,5): | ||
+ | display.set_pixel(i, | ||
+ | sleep(100) | ||
+ | display.clear() | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | </ | ||
=== Aufgaben RD === | === 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 = '' | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | |||
+ | </ |