Pinnummern bei Rotationssensor vertauscht um Richtung zu korrigieren, Anweisungen für Spieler einheitlicher und genauer gemacht

This commit is contained in:
Franziska Gerold 2025-12-19 02:07:57 +11:00
parent 6ba17e9576
commit 04c89df25b

View File

@ -5,14 +5,11 @@ from gpiozero import RotaryEncoder
laser = Button(17) #Die Zahl entspricht dem Pin auf dem ARPI600 Board laser = Button(17) #Die Zahl entspricht dem Pin auf dem ARPI600 Board
sound = Button(18, pull_up=True) sound = Button(18, pull_up=True)
rotate = RotaryEncoder(21, 20) rotate = RotaryEncoder(20, 21)
tilt = Button(23) tilt = Button(23)
def score(x):
pass
def command_tilt(): def command_tilt():
print("waiting to get tilted...") print("Tilt me!")
result = tilt.wait_for_press(timeout=10) result = tilt.wait_for_press(timeout=10)
print(f"Result: {result}") print(f"Result: {result}")
if result: if result:
@ -24,7 +21,7 @@ def command_tilt():
def command_blind(): def command_blind():
print('waiting for eye problems...') print('Blind me!')
result = laser.wait_for_press(timeout=10) result = laser.wait_for_press(timeout=10)
print(f"Result: {result}") print(f"Result: {result}")
if result: if result:
@ -33,7 +30,7 @@ def command_blind():
return -1 return -1
def command_scream(): def command_scream():
print('waiting for sound...') print('Make noise at me!')
result = sound.wait_for_press(timeout=10) result = sound.wait_for_press(timeout=10)
print(f"Result: {result}") print(f"Result: {result}")
if result: if result:
@ -43,7 +40,7 @@ def command_scream():
return -1 return -1
def command_spin_clockwise(): def command_spin_clockwise():
print("waiting for spinning... clockwise!") print("Spin me... clockwise!")
result = rotate.wait_for_rotate_clockwise(timeout=10) result = rotate.wait_for_rotate_clockwise(timeout=10)
if result: if result:
return 1 return 1
@ -51,23 +48,21 @@ def command_spin_clockwise():
return -1 return -1
def command_spin_counter_clockwise(): def command_spin_counter_clockwise():
print("waiting for spinning... counter clockwise!") print("Spin me... counter clockwise!")
result = rotate.wait_for_rotate_counter_clockwise(timeout=10) result = rotate.wait_for_rotate_counter_clockwise(timeout=10)
if result: if result:
return 1 return 1
else: else:
return -1 return -1
def sound_was_held():
print('You screamed long enough!')
def main(): def main():
score = 0 score = 0
result = 0 result = 0
sound.when_held = sound_was_held print("Raspberry will now tell you what to do.")
print("Let's play a Round of 'Raspberry says'!") print("Every correct action will give you a point.")
list_command_choices =[command_tilt] # [command_spin_clockwise, command_spin_counter_clockwise] #command_spin, command_tilt, command_blind_ command_scream print("How many can you get?")
print("Let's go!")
list_command_choices =[command_tilt, command_spin_clockwise, command_spin_counter_clockwise, command_blind, command_scream]
while result != -1: while result != -1:
score += result # war zuerst zwei Zeilen weiter unten, hat dann aber nach einer falschen Runde den Score erhöht score += result # war zuerst zwei Zeilen weiter unten, hat dann aber nach einer falschen Runde den Score erhöht
time.sleep(0.5) time.sleep(0.5)