import RPi.GPIO as GPIO import time import pygame from threading import Thread GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) abfrage_blaulicht = "False" pygame.mixer.init() pygame.mixer.pre_init(44100, 16, 2, 512) land_sfx = pygame.mixer.Sound("/home/pi/Desktop/DIN_Land.ogg") stadt_sfx = pygame.mixer.Sound("/home/pi/Desktop/DIN_Stadt.ogg") pygame.mixer.Sound.set_volume(land_sfx, 0.2) pygame.mixer.Sound.set_volume(stadt_sfx, 0.2) GPIO.setup(13, GPIO.IN) GPIO.setup(26, GPIO.IN) GPIO.setup(22, GPIO.IN) GPIO.setup(23, GPIO.OUT) GPIO.setup(24, GPIO.OUT) #################Abfrage##################################### def Abfrage(): global abfrage_blaulicht while True: if GPIO.input(13) == 1 and abfrage_blaulicht == "False": abfrage_blaulicht = "True" time.sleep(1) if GPIO.input(13) == 1 and abfrage_blaulicht == "True": abfrage_blaulicht = "False" time.sleep(1) ##################Blaulicht#################################### def Blaulicht(): global abfrage_blaulicht while True: if abfrage_blaulicht == "True": while True: GPIO.output(23, GPIO.HIGH) time.sleep(0.04) GPIO.output(23, GPIO.LOW) time.sleep(0.04) GPIO.output(23, GPIO.HIGH) time.sleep(0.04) GPIO.output(23, GPIO.LOW) time.sleep(0.4) GPIO.output(24, GPIO.HIGH) time.sleep(0.04) GPIO.output(24, GPIO.LOW) time.sleep(0.04) GPIO.output(24, GPIO.HIGH) time.sleep(0.04) GPIO.output(24, GPIO.LOW) if abfrage_blaulicht == "False": GPIO.output(23, GPIO.LOW) GPIO.output(24, GPIO.LOW) break ##################Horn#################################### def Horn(): while True: if GPIO.input(26) == 1 and GPIO.input(22) == 1: land_sfx.play() if GPIO.input(26) == 1 and GPIO.input(22) == 0: stadt_sfx.play() horn_fred = Thread(target=Horn) blaulicht_fred = Thread(target=Blaulicht) abfrage_fred = Thread(target=Abfrage) blaulicht_fred.start() horn_fred.start() abfrage_fred.start()