Skip to content

Instantly share code, notes, and snippets.

@pato
Created August 6, 2013 17:24
Show Gist options
  • Save pato/6166573 to your computer and use it in GitHub Desktop.
Save pato/6166573 to your computer and use it in GitHub Desktop.
emClock - Raspberry Pi Clock + email checker using Adafruit's LED matrices and a piface
#!/usr/bin/python
import time
import datetime
import feedparser
import threading
from Adafruit_8x8 import EightByEight
import piface.pfio as pfio
pfio.init()
grid = EightByEight(address=0x70)
grid2 = EightByEight(address=0x71)
print "Press CTRL+Z to exit"
n0 = [[1,1,1],
[1,0,1],
[1,0,1],
[1,0,1],
[1,1,1]]
n1 = [[0,0,1],
[0,0,1],
[0,0,1],
[0,0,1],
[0,0,1]]
n2 = [[1,1,1],
[0,0,1],
[1,1,1],
[1,0,0],
[1,1,1]]
n3 = [[1,1,1],
[0,0,1],
[0,1,1],
[0,0,1],
[1,1,1]]
n4 = [[1,0,1],
[1,0,1],
[1,1,1],
[0,0,1],
[0,0,1]]
n5 = [[1,1,1],
[1,0,0],
[1,1,1],
[0,0,1],
[1,1,1]]
n6 = [[1,1,1],
[1,0,0],
[1,1,1],
[1,0,1],
[1,1,1]]
n7 = [[1,1,1],
[0,0,1],
[0,0,1],
[0,0,1],
[0,0,1]]
n8 = [[1,1,1],
[1,0,1],
[1,1,1],
[1,0,1],
[1,1,1]]
n9 = [[1,1,1],
[1,0,1],
[1,1,1],
[0,0,1],
[0,0,1]]
nums = [n0,n1,n2,n3,n4,n5,n6,n7,n8,n9]
def plotMatrix(m,wgrid):
for ix, x in enumerate(m):
for iy, y in enumerate(x):
if y==1:
wgrid.setPixel(iy,ix)
else:
wgrid.clearPixel(iy,ix)
def plotNum(c,n):
if c<2:
wgrid = grid
else:
wgrid = grid2
for ix, x in enumerate(nums[n]):
for iy, y in enumerate(x):
if y==1:
wgrid.setPixel(iy+((c%2)*5),ix+2)
def notifySound(count):
for x in range(0,count):
pfio.digital_write(6,1)
time.sleep(0.8)
pfio.digital_write(6,0)
time.sleep(0.2)
def led(led,val):
#7 - Gmail led
#6 - speaker
pfio.digital_write(led,val)
pastEmails = 0
def emailCheck():
global pastEmails
emails = newmails = int(feedparser.parse("https://USERNAME:PASSWORD@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
if emails > pastEmails:
pastEmails = emails
notifySound(emails)
led(7,1)
elif emails < 2:
led(7,0)
pastLink = ""
def fbCheck():
global pastLink
fbFeed = feedparser.parse("https://www.facebook.com/feeds/notifications.php?id=###########&viewer=##########&key=##########&format=rss20")
link = fbFeed["entries"][0]["link"]
if link != pastLink:
pastLink = link
notifySound()
led(6,1)
else:
led(6,0)
pastMinute = 0
def clockStep():
global pastMinute
now = datetime.datetime.now()
hour = now.hour
minute = now.minute
second = now.second
if minute != pastMinute:
pastMinute = minute
grid.clear()
grid2.clear()
plotNum(0,hour/10)
plotNum(1,hour%10)
plotNum(2,minute/10)
plotNum(3,minute%10)
else:
if (second<32):
grid.setPixel(second/4,0)
else:
grid2.setPixel((second-32)/4,0)
def do_every(interval, worker_func, iterations = 0):
if iterations != 1:
threading.Timer (
interval,
do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1]
).start();
worker_func();
do_every(1,clockStep)
do_every(10,emailCheck)
# thread.start_new_thread(fbCheck())
# thread.start_new_thread(clockStep())
# thread.start_new_thread(emailCheck())
@dav-s
Copy link

dav-s commented Aug 12, 2013

Good thing you left your login information out hahaha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment