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 [2026-01-05 13:27] – sca | gf_informatik:microbit_sca [2026-01-05 14:36] (aktuell) – sca | ||
|---|---|---|---|
| Zeile 581: | Zeile 581: | ||
| </ | </ | ||
| - | === C5 – Variante A === | + | === C5 === |
| + | |||
| + | Variante 1 | ||
| <code python> | <code python> | ||
| from microbit import * | from microbit import * | ||
| - | my_images | + | all_leds |
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | ] | ||
| - | for i in range(0, 9, 1): | + | while True: |
| - | | + | # Variante 1 |
| - | | + | ax,ay,az = accelerometer.get_values() |
| - | | + | |
| + | # Variante 2 | ||
| + | ax = accelerometer.get_x() | ||
| + | | ||
| + | | ||
| - | my_pos | + | # Gesamtbeschleunigung |
| - | + | a = (ax*ax + ay**2 + az**2)**0.5 | |
| - | while True: | + | if a < 1200: |
| - | | + | |
| - | | + | elif a <= 1500: |
| - | | + | display.show(all_leds[1]) |
| + | | ||
| + | display.show(all_leds[2]) | ||
| + | | ||
| + | display.show(all_leds[3]) | ||
| + | elif a <= 2400: | ||
| + | | ||
| + | elif a <= 2700: | ||
| + | display.show(all_leds[5]) | ||
| + | elif a <= 3000: | ||
| + | display.show(all_leds[6]) | ||
| + | elif a <= 3300: | ||
| + | display.show(all_leds[7]) | ||
| + | elif a <= 3600: | ||
| + | display.show(all_leds[8]) | ||
| else: | else: | ||
| - | | + | display.show(all_leds[9]) |
| - | | + | |
| + | print(a) | ||
| + | sleep(400) | ||
| </ | </ | ||
| - | === C5 – Variante | + | Variante |
| <code python> | <code python> | ||
| + | # Imports go at the top | ||
| from microbit import * | from microbit import * | ||
| + | import math | ||
| my_images = [] | my_images = [] | ||
| - | for i in range(0, 9, 1): | + | all_leds = [ |
| - | | + | Image("00000:00000: |
| - | | + | Image(" |
| - | | + | |
| - | + | | |
| - | display.show(my_images, delay = 200, loop = True) | + | Image(" |
| - | </ | + | Image(" |
| - | + | Image(" | |
| - | === C6 === | + | Image(" |
| - | <code python> | + | |
| - | from microbit import * | + | |
| - | + | ] | |
| - | my_images = [] | + | |
| - | my_pos = 0 | + | |
| - | + | ||
| - | for i in range(0, 9, 1): | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| while True: | while True: | ||
| - | | + | |
| - | sleep(100) | + | a = math.sqrt(x*x+y*y+z*z) |
| - | if my_pos < len(my_images) | + | |
| - | | + | if strength > 9: |
| - | else: | + | |
| - | | + | elif strength < 0: |
| - | display.show(my_images[my_pos]) | + | |
| + | print(strength) | ||
| + | display.show(all_leds[strength]) | ||
| + | sleep(200) | ||
| </ | </ | ||
| - | === C7 === | ||
| - | <code python> | ||
| - | from microbit import * | ||
| - | |||
| - | my_images = [] | ||
| - | my_pos = 0 | ||
| - | |||
| - | for i in range(0, 10, 1): | ||
| - | my_img = Image() | ||
| - | my_img.fill(i) | ||
| - | my_images.append(my_img) | ||
| - | |||
| - | while True: | ||
| - | xAcceleration = accelerometer.get_x() | ||
| - | # xAcceleration von +/-2040 nach 0...9 umrechnen: | ||
| - | my_pos = abs(xAcceleration) // 205 | ||
| - | print(my_pos) | ||
| - | display.show(my_images[my_pos]) | ||
| - | </ | ||
| ++++ | ++++ | ||
| </ | </ | ||