From 1c09f1352846629acc5d6aacc1123dbeee3b4611 Mon Sep 17 00:00:00 2001 From: Franziska Gerold Date: Thu, 18 Dec 2025 14:05:12 +0100 Subject: [PATCH] =?UTF-8?q?neue=20Klasse=20f=C3=BCr=20Rotationssensor=20im?= =?UTF-8?q?portiert,=20Rotationssensor=20mit=20zwei=20commands=20eingebaut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bop_it_sensors.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Bop_it_sensors.py b/Bop_it_sensors.py index 05f2f77..6ecc18c 100644 --- a/Bop_it_sensors.py +++ b/Bop_it_sensors.py @@ -1,9 +1,11 @@ import random import time from gpiozero import Button +from gpiozero import RotaryEncoder -laser = Button(17) +laser = Button(17) #Die Zahl entspricht dem Pin auf dem ARPI600 Board sound = Button(18, pull_up=True) +rotate = RotaryEncoder(21, 20) def score(x): pass @@ -31,18 +33,28 @@ def command_scream(): result = sound.wait_for_press(timeout=10) print(f"Result: {result}") if result: - time.sleep(0.3) + time.sleep(0.3) #soll verhindern, dass dasGeräuschsignal aus der vorherigen Runde gezählt wird return 1 else: return -1 -def command_spin(): - action = input() - if action == "0": +def command_spin_clockwise(): + print("waiting for spinning... clockwise!") + result = rotate.wait_for_rotate_clockwise(timeout=10) + if result: return 1 else: return -1 +def command_spin_counter_clockwise(): + print("waiting for spinning... counter clockwise!") + result = rotate.wait_for_rotate_counter_clockwise(timeout=10) + if result: + return 1 + else: + return -1 + + def sound_was_held(): print('You screamed long enough!') @@ -51,9 +63,11 @@ def main(): result = 0 sound.when_held = sound_was_held print("Let's play a Round of 'Raspberry says'!") - list_command_choices = [command_scream, command_blind]# command_blind, command_spin, command_tilt + list_command_choices = [command_spin_clockwise, command_spin_counter_clockwise] #command_spin, command_tilt, command_blind_ command_scream while result != -1: score += result # war zuerst zwei Zeilen weiter unten, hat dann aber nach einer falschen Runde den Score erhöht + time.sleep(0.5) + print("Get ready for the next round!") round = random.choice(list_command_choices) result = round() print(f"Game over! Your Score is {score}") @@ -61,4 +75,4 @@ def main(): -main() +main() \ No newline at end of file