Skip to content

Instantly share code, notes, and snippets.

@pdp7
Created September 8, 2012 10:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pdp7/3673183 to your computer and use it in GitHub Desktop.
Save pdp7/3673183 to your computer and use it in GitHub Desktop.
[timetemp] python script for Raspberry Pi to display time and temp on 7-segment display
#!/usr/bin/env python
# element14 Blog post:
# http://www.element14.com/community/groups/raspberry-pi/blog/2012/09/26/time-temp-display-for-raspberry-pi
# Based on Simon Monk's library:
# http://www.doctormonk.com/2012/08/led-clock-using-raspberry-pi.html
#
import i2c7segment as display
import time
import sensors
from time import sleep
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
disp = display.Adafruit7Segment()
while True:
if ( GPIO.input(23) == False ):
temp = 0.0
sensors.init()
try:
for chip in sensors.iter_detected_chips():
for feature in chip:
temp = '%.2f' % ( feature.get_value() * 9/5 + 32 )
finally:
sensors.cleanup()
disp.print_str(temp);
disp.write_display()
time.sleep(3)
disp.write_digit_raw(0,0);
disp.write_digit_raw(1,0);
disp.write_digit_raw(2,0);
disp.write_digit_raw(4,0);
h = time.localtime().tm_hour
m = time.localtime().tm_min
disp.print_int(h * 100 + m)
disp.draw_colon(True)
disp.write_display()
time.sleep(0.5)
disp.draw_colon(False)
disp.write_display()
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment