I am a bit of newbie to programming on the raspberry pi.
I am trying to develop a dementia style clock for my mum with help from my 7 year old son for a Christmas present for my mum. I think it would be nice as a learning exercise to do something bespoke which could have an open source development?
Many years ago I dabbled in programming on a BBC micro with basic and a little assembly language that was gleaned and mostly copied and hacked from magazines at the time, when I was maybe 16-17? So I kind of understand loops and procedure calls but don't really get object oriented programming?
The idea of the project is for a picture/audio frame in my mum's kitchen.
The idea:
My mum walks into the kitchen in the morning , a PIR triggers playing BBC radio 3 (she often forgets to put the radio on)
The script plays radio 3 and then prompts my mum at various times during the day with audio prompts and pictures with text.
0900: "Grandma, it's time for breakfast..." voiced by my son or family member
1200: "Mum it's time for lunch..."
1700: "Grandma its time for dinner"
1800: "Mum its time to take your medication"
etc
I have managed to make a python script that in theory would do the audio part, but it is clumsy.
It would involve a lot of
"if hour is 9 then fade down radio stream by incrementally reducing the system volume, stop the audio stream , wait, then fade sys system sound up, play audio file "Grandma.." then fade down.....etc"
Obviously this project could be evolved into a massive project with a CMS backend for family members, integrated with a google calendar with appointment reminders etc but I want to keep it simple for the time being. Christmas is soon!!
I had thought about having a sort of config file either local or online that had for instance:
09:00, "Breakfast...wav", "Breakfast.jpg"
12:00, "Lunchtime...wav etc
that could be read at startup into an array? that could be passed to a generic audio/picture procedure that could break a general screensaver and play the necessary audio and pictures?
*** Can anyone give some hints to tutorials or ideas of program structure?
*** Should I stick with python or is there a better language to use?
*** Can anyone suggest a suitable IMAGE module for a really simple image rotater, no effects just cuts is fine for now., I have been dabbling with a pygame script?
below is my poor code which has some testing stuff in it, ie the main loop is arbitary and not configured for the PIR or an end time. The volume settings are to do some level shifting between the stream and my recording which needs to be normalised/level changed.
Code: Select all
import pygame
import datetime
import os
import time
import vlc
pygame.mixer.init()
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
os.system("amixer sset 'Master' 80%")
def fadedown():
for x in range(0, 5):
os.system("amixer sset 'Master' 5%-")
time.sleep(0.5)
return
def fadeup():
for x in range(0, 5):
os.system("amixer sset 'Master' 5%+")
time.sleep(0.5)
return
i = datetime.datetime.now()
h = i.hour
m = i.minute
s = i.second
print ("Start Up Current hour = %s" %i.hour)
station="http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_three.m3u8"
if h>=0 and h<24:
player = vlc.MediaPlayer(station)
player.play()
print ("moving on")
while True:
i = datetime.datetime.now()
h = i.hour
m = i.minute
s = i.second
print ("Current hour = %s" %i.hour)
if h==12 and m==0 and s<10:
fadedown()
player.pause()
time.sleep(1)
fadeup()
os.system("amixer sset 'Master' 100%")
audiofile='/home/pi/Music/Lunchtime.mp3'
player = vlc.MediaPlayer(audiofile)
player.play()
time.sleep(2)
os.system("amixer sset 'Master' 80%")
fadedown()
player = vlc.MediaPlayer(station)
player.play()
fadeup()
time.sleep(10)
print ("loop")
Simon