#Bytebox Firmware V0.7 #Thirdbyte #Imports import os import sys import glob import time import datetime import RPi.GPIO as GPIO import urllib as web from blinkstick import blinkstick from PIL import Image import Adafruit_BMP.BMP085 as BMP085 from Adafruit_LED_Backpack import SevenSegment #Firmware Version Number fw_version = 0.7 #Opens RGB Image im = Image.open("RGBTEMP.jpg") #Defines own range functions for 0.1 stepping def my_range(start, end, step): while start <= end: yield start start += step #set blinkstick bstick = blinkstick.find_first() #set BMP180 Temp sensor = BMP085.BMP085() #Set 7 seg display display = SevenSegment.SevenSegment() #starts display display.begin() #Read and convert temp data def read_temp(): temp_c = sensor.read_temperature() return temp_c #Start up light show def startup(): for i in range(5): bstick.morph(hex=bstick.set_random_color(), duration=1000, steps=50) #Flashes LED on error exception def error_blink(): bstick.pulse(name="red", repeats=5, duration=1000, steps=50) #Sends temp data to ThingSpeak def log_temp(input): URL = "https://api.thingspeak.com/update?key=YZSOXYBLBD28WKZV&headers=false" URL = URL + "&field1"+"="+str(input) print(URL) web.urlopen(URL).read() time.sleep(300) #Checks if it's quiet time, returns true or false def quiet_time(): #Get current time current_time = datetime.datetime.now().time() qstart = datetime.time(hour = 22) qend = datetime.time(hour = 06) if qstart.hour >= current_time.hour and qend.hour > current_time.hour: return True else: return False def log_local(tempa): current_time = datetime.datetime.now().time() f = open('Templog.txt','a') f.write("\nTemp: " + str(tempa) + " Date/Time: " + str(datetime.datetime.now()) + "\n") f.close() #Converts temp to RGB value using magic. def temptoRGB(temp): pix = im.load() list = [] for x in my_range(12, 30, 0.1): list.append(round(x,1)) rgbval= pix[list.index(temp),5] #Get the RGBA Value of the a pixel of an image r = rgbval[0] g = rgbval[1] b = rgbval[2] return rgbval startup() #Main loop while True: temp = read_temp() print(temp) timechk = False #quiet_time() #checks for quiet time if timechk == False: col = temptoRGB(temp) bstick.morph(red = col[0], green = col[1], blue = col[2], duration=1000, steps=50) display.clear() display.print_number_str(str(temp) + "c", justify_right=False) display.write_display() #log_local(temp) try: log_temp(temp) except: error_blink() display.clear()