import machine
import time
from machine import Pin

starttime = ["08:09","08:11","20:00"]

p27 = Pin(27, Pin.OUT)
rtc = machine.RTC()
rtc.datetime((2022, 6, 29, 3, 8, 8, 36, 0))
zeit = "00:00"

def readtime():
  global zeit
  datetime = rtc.datetime()
  h= (datetime[4])
  m = (datetime[5])
  H=str(h)
  M=str(m)
  if (len (H) < 2):
    H = "0" + H
  if (len (M) < 2):
    M = "0" +M

  #print(H + ":" + M)
  zeit = H + ":" + M
  #print(zeit)

def pruefen2():
  for x in starttime:
    if zeit == x:
     schalten()
    else:
      p27.off() 
  
def schalten():
  start = time.ticks_ms() # get millisecond counter

  while (time.ticks_ms < (start + 60000)):
    p27.on()




def pruefen():
  if zeit == "08:09":
   print ("Startzeit erkannt")
   p27.on()
  else:
   print ("Zeit stimmt nicht")
   p27.off()


while (1):
  readtime()
  print(zeit)
  pruefen2()
  schalten()
  
  time.sleep(60)