Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung | |||
| gf_informatik:microbit_sca [2026-01-05 13:30] – [Lösungen] sca | gf_informatik:microbit_sca [2026-01-05 14:36] (aktuell) – sca | ||
|---|---|---|---|
| Zeile 583: | Zeile 583: | ||
| === C5 === | === C5 === | ||
| + | Variante 1 | ||
| + | <code python> | ||
| + | from microbit import * | ||
| + | |||
| + | all_leds = [ | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | Image(" | ||
| + | ] | ||
| + | |||
| + | while True: | ||
| + | # Variante 1 | ||
| + | ax,ay,az = accelerometer.get_values() | ||
| + | | ||
| + | # Variante 2 | ||
| + | ax = accelerometer.get_x() | ||
| + | ay = accelerometer.get_y() | ||
| + | az = accelerometer.get_z() | ||
| + | |||
| + | # Gesamtbeschleunigung | ||
| + | a = (ax*ax + ay**2 + az**2)**0.5 | ||
| + | if a < 1200: | ||
| + | display.show(all_leds[0]) | ||
| + | elif a <= 1500: | ||
| + | display.show(all_leds[1]) | ||
| + | elif a <= 1800: | ||
| + | display.show(all_leds[2]) | ||
| + | elif a <= 2100: | ||
| + | display.show(all_leds[3]) | ||
| + | elif a <= 2400: | ||
| + | display.show(all_leds[4]) | ||
| + | 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: | ||
| + | display.show(all_leds[9]) | ||
| + | | ||
| + | print(a) | ||
| + | sleep(400) | ||
| + | </ | ||
| + | |||
| + | Variante 2 (elegant) | ||
| <code python> | <code python> | ||
| # Imports go at the top | # Imports go at the top | ||