Created
September 8, 2012 10:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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