Advertisement
aBabyPenguin

LightTimer

Mar 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. #LightTimer
  2. import time
  3. import RPi.GPIO as gpio
  4. from gpiozero import LED, PWMLED
  5.  
  6. #gpio.setmode(gpio.BOARD)
  7. #gpio.setup(5, gpio.OUT)
  8.  
  9. lights = PWMLED(3)
  10.  
  11. h = time.localtime()[3]
  12.  
  13. while True:
  14.     try:
  15.         h = time.localtime()[3]
  16.         if h >= 18 or h <= 4 :
  17.             #gpio.output(5, True)
  18.             lights.pulse(10,10)
  19.            
  20.         else:
  21.             #gpio.output(5, False)
  22.             lights.off()
  23.            
  24.         time.sleep(20*60)
  25.     except KeyboardInterrupt:
  26.         #gpio.output(5, False)
  27.         #gpio.cleanup()
  28.         lights.off()
  29.         raise
  30.  
  31. #gpio.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement