Tuesday 29 November 2016

Pi Light and Movie Quote Alarm Clock

Sorry, No documentation on this one. Rough and ready test program.

Turns a blue LED on in the morning (and evening..don't ask) to wake me up, but also plays a random selection from a bank of quotes.  

from gpiozero import LED
from time import sleep
import datetime
import os
import random

led = LED(4)

overRide='auto'
amOn=datetime.time(05,50,00)
amOff=datetime.time(06,30,00)
pmOn=datetime.time(21,30,00)
pmOff=datetime.time(22,45,00)

print (pmOff)
soundTrigger=0
while True:
        while overRide=='auto':

                timeNow=datetime.datetime.now().time()
                soundchoice = str(random.randint(1,5))
                playsound=('aplay '+soundchoice+'.wav')
                if timeNow>pmOn and timeNow<pmOff or timeNow>amOn and timeNow<amOff:
                        led.on()
                        print('led on')
                        soundTrigger+=1
                        if soundTrigger==1:
                                os.system(playsound)
                else:
                        led.off()
                        print('led off')
                        soundTrigger=0
                sleep(60)

No comments:

Post a Comment