Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
gf_informatik:microbit_und_roboter_programmieren:repetitionsaufgaben [2023-10-03 20:18] – [Lösungen] gragf_informatik:microbit_und_roboter_programmieren:repetitionsaufgaben [2023-10-04 14:29] (aktuell) – [Aufgaben RD] gra
Zeile 124: Zeile 124:
  
 === Aufgaben RA === === Aufgaben RA ===
-<nodisp 2>+<nodisp 1>
 ++++ RA1:|  ++++ RA1:| 
   <code python>   <code python>
Zeile 217: Zeile 217:
 </nodisp> </nodisp>
 === Aufgaben RB === === Aufgaben RB ===
 +<nodisp 1>
 +++++ RB1:| 
 +<code python>
 +from microbit import *
 +
 +def make_heart_image(b):
 +    heart_string = '09090:99999:99999:09990:00900'
 +    new_string = heart_string.replace('9',str(b))
 +    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))
 +</code>
 +++++
 +
 +++++ RB2:| 
 +<code python>
 +from microbit import *
 +
 +def draw_horizontal_line(y_pos):
 +    display.clear()
 +    display.set_pixel(0,y_pos,9)
 +    display.set_pixel(1,y_pos,9)
 +    display.set_pixel(2,y_pos,9)
 +    display.set_pixel(3,y_pos,9)
 +    display.set_pixel(4,y_pos,9)
 +
 +y = 0
 +while True:
 +    if button_a.was_pressed():
 +        y = (y + 1) % 5
 +        draw_horizontal_line(y)
 +</code>
 +++++
 +
 +++++ 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("X: " + str(x * factor) + unit_string)
 +    print("Y: " + str(y * factor) + unit_string)
 +    print("Z: " + str(z * factor) + unit_string)
 +
 +unit = 0
 +while True:
 +    if button_a.was_pressed():
 +        unit = (unit + 1) % 3
 +    print_acc_values(unit)
 +    sleep(500)
 +</code>
 +++++
 +
 +++++ 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/a_max * 9)
 +    return a
 +
 +while True:
 +    display.show(get_total_acc())
 +</code>
 +++++
 +
 +</nodisp>
 === Aufgaben RC === === Aufgaben RC ===
 +<nodisp 1>
 +++++ RC1:| 
 +<code python>
 +from microbit import *
 +import random 
 +
 +while True:
 +    column = random.randint(0,4)
 +    for row in range(0,5):
 +        display.set_pixel(column, row, 9)
 +        sleep(40)
 +        display.clear()
 +</code>
 +++++
 +
 +++++ RC2:| 
 +<code python>
 +from microbit import *
 +import random 
 +
 +def shoot(a_shoots):
 +    row = random.randint(0,4)
 +    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, stop_column, step):
 +           display.set_pixel(column, row, 9)
 +           sleep(40)
 +           display.clear()
 +
 +while True:
 +    if button_a.was_pressed():
 +        shoot(True)
 +    if button_b.was_pressed():
 +        shoot(False)
 +</code>
 +++++
 +
 +++++ 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 + '0'
 +    if button_b.was_pressed():
 +        binary = binary + '1'
 +    if pin_logo.is_touched():
 +        print(binary)
 +        print(binary_to_decimal(binary))
 +        sleep(100)
 +        binary = ''
 +</code>
 +++++
 +
 +++++ RC4:| 
 +<code python>
 +from microbit import *
 +
 +while True:
 +    for i in range(0,5):
 +        display.set_pixel(i, 4-i,9)
 +        sleep(100)
 +    display.clear()
 +    for i in range(0,5):
 +        display.set_pixel(i, i, 9)
 +        sleep(100)
 +    display.clear()
 +</code>
 +++++
 +
 +</nodisp>
 === 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])
 +</code>
 +++++
 +
 +++++ RD2:| 
 +<code python>
 +from microbit import *
 +import random
 +
 +subjekte = ["Karls Katze", "Albert Einstein", "Lauryn Hill", "Eine Blume", "LeBron James", "Eine Pizza", "Taylor Swift", "Die Sonne"]
 +verben = ["liebt", "betrachtet", "baut", "malt", "erfindet", "liest", "schreibt", "singt"]
 +adjektive = ["schnell", "glücklich", "groß", "konzentiert", "zitternd", "fröhlich", "begeistert", "trübselig"]
 +objekte = ["einen Apfel", "eine Geschichte", "einen Kaffee", "einen Film", "die Pyramiden", "eine Reise", "einen Brief", "Leonardo da Vinci"]
 +
 +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 = "{} {} {} {}.".format(subjekt,verb,adjektiv,objekt)
 +        print(satz)
 +</code>
 +++++
 +
 +++++ RD3:| 
 +<code python>
 +from microbit import *
 +
 +buchstaben = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
 +
 +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 = ''
 +</code>
 +++++
 +
 +
 +</nodisp>
  • gf_informatik/microbit_und_roboter_programmieren/repetitionsaufgaben.1696364324.txt.gz
  • Zuletzt geändert: 2023-10-03 20:18
  • von gra