[/code]Hallo, erstmal vielen Dank für die Kommentare. Alles richtig und habe verstanden, aber trotzdem wird nachdem ich die zeitgrenzen gesetzt habe, nicht die die Schleife unterbrochen, bzw led ausgeschaltet.
Code: Alles auswählen
#!/usr/bin/env python3
import datetime
import time
import snap7
from RPi import GPIO
ADDRESS_TEMPERATURE_POOL = "VW1118"
ADDRESS_TEMPERATURE_AUSSEN = "VW1120"
DELAY_TIME = 0.003
START_TIME=datetime.time(4,35)
END_TIME=datetime.time(19,43)
# kontrolliert Programm beenden mit ctrl + c
# python /home/pi/Desktop/finale/masterpool.py
# Pinbelegung raspberry
# led segmente pi 4B
# a=4, b=27, c=22, d=5, e=6, f=26, g=23, point=24
# lede module
# digit1=12,digit2=13,digit3=20,digit4=19,
SEGMENT_PINS = (4, 27, 22, 5, 6, 26, 23, 24)
DIGIT_PINS = (12, 13, 20, 19)
DIGITS = {
" ": [0, 0, 0, 0, 0, 0, 0],
"0": [1, 1, 1, 1, 1, 1, 0],
"1": [0, 1, 1, 0, 0, 0, 0],
"2": [1, 1, 0, 1, 1, 0, 1],
"3": [1, 1, 1, 1, 0, 0, 1],
"4": [0, 1, 1, 0, 0, 1, 1],
"5": [1, 0, 1, 1, 0, 1, 1],
"6": [1, 0, 1, 1, 1, 1, 1],
"7": [1, 1, 1, 0, 0, 0, 0],
"8": [1, 1, 1, 1, 1, 1, 1],
"9": [1, 1, 1, 1, 0, 1, 1],
"o": [1, 0, 0, 0, 0, 1, 1], # Gradsymbol
"-": [0, 0, 0, 0, 0, 0, 1],
}
def initialize():
GPIO.setmode(GPIO.BCM)
for pin in SEGMENT_PINS + DIGIT_PINS:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
def print_segment(digit_pin, character, point=False):
GPIO.output(digit_pin, 1) # Turn on Digit
for pin, value in zip(SEGMENT_PINS, DIGITS[character]):
GPIO.output(pin, value)
GPIO.output(SEGMENT_PINS[-1], point) # Display point?
time.sleep(DELAY_TIME)
GPIO.output(digit_pin, 0)
def print_digits(text, point_pin=0):
for pin, character in zip(DIGIT_PINS, text):
print_segment(pin, character, pin == point_pin)
def print_temperature(temperature, station):
if temperature is None:
print("Kein Wert", temperature)
point_pin = 0
temperature = "----"
else:
#print(station, "=", temperature/10)
temperature = f'{temperature*0.1:4.1f}o'.replace('.','')
if len(temperature) > 4:
point_pin = 0
temperature = temperature[:3] + 'o'
else:
point_pin = DIGIT_PINS[1]
print_digits(temperature, point_pin)
def print_zeit():
now = datetime.datetime.now()
#print("time:", now.strftime("%H:%M"))
print_digits(now.strftime("%H%M"), DIGIT_PINS[1])
print_digits(now.strftime("%H%M"), DIGIT_PINS[2])
def show_value():
try:
plc = snap7.logo.Logo()
plc.connect("192.168.178.6", 1118, 1245)
plc.get_connected()
while True:
start = time.monotonic()
TEMP1=plc.read(ADDRESS_TEMPERATURE_POOL)
TEMP2=plc.read(ADDRESS_TEMPERATURE_AUSSEN)
while time.monotonic() - start < 10.3:
print_zeit()
while time.monotonic() - start < 20.6:
#temperatur = plc.read(ADDRESS_TEMPERATURE_POOL)
print_temperature(TEMP1, "Temp. Pool")
while time.monotonic() - start < 30.9:
#temperatur = plc.read(ADDRESS_TEMPERATURE_AUSSEN)
print_temperature(TEMP2, "Temp. Außen")
finally:
plc.disconnect()
plc.destroy()
def zeitraum():
now = datetime.datetime.now()
start_date = datetime.datetime.combine(now, START_TIME)
end_date = datetime.datetime.combine(now, END_TIME)
return start_date <= now <= end_date
def digit_aus():
GPIO.output(19, 0) #Turn off Digit One
GPIO.output(12, 0) #Turn on Digit One
GPIO.output(13, 0) #Turn on Digit One
GPIO.output(20, 0) #Turn on Digit One
GPIO.output(24, 0) #Turn on Digit One
def main():
try:
initialize()
while True:
try:
if zeitraum():
show_value()
else:
print("off")
digit_aus()
except Exception as error:
print(error)
#time.sleep(1)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
if __name__ == "__main__":
main()