A useful script for RGB displays

hi all,

After searching the Internet for one, I wrote a quick Python module to convert a value (most likley a temperature) to a cold-hot RGB colour - I’ve found this useful on the DOTHAT for representing the Pi’s internal CPU temp and also outside weather. Could be used for a lot of other things. The module has two functions - temp_rgb - takes a value, and a min-max range, and outputs an RGB tuple. it rebases the value you enter depending on the min/max range.

The other “get_temp”, returns the CPU temperature of the Pi.

(Gist: https://gist.github.com/philipok-1/99de9fa271a27e17b0ff62fbe2c0e3e6)

PS - the array of RGB colours was adapted from the excellent blog:

Unfortunately, your gist is full of unformatted javascript, writing the text of your Python code. You need to take the .js off the end.

Here’s an updated link: https://gist.github.com/philipok-1/99de9fa271a27e17b0ff62fbe2c0e3e6

yes! thanks, just realised… reposted.

My first post - sorry…

unfortunately it doesn’t seem to be working for me.
I just get the error list index is out of range

import rgb_temp as t
import time
while True:


I also edited your file to this

import re, subprocess

rgb_array=[(0, 100, 255), (0, 116, 255), (0, 132, 255), (0, 148, 255), (0, 164, 255), (0, 180, 255), (0, 196, 255), (0, 212, 255), (0, 228, 255), (0, 255, 244), (0, 255, 208), (0, 255, 168), (0, 255, 131)]

def temp_rgb(temp, min, max):

    if temp<min:
    elif temp>max:
    index = (((temp - min) * (53 - 0)) / (max - min)) + 0


    return output

def get_temp():

    temp=subprocess.check_output(["/opt/vc/bin/vcgencmd measure_temp"], shell=True)
    out=re.search(r'\d+\.\d+', temp)
    return str(out.group(0))

def main():
print temp_rgb(-20, -5, 30)

if name == “main”:


as there were a few errors I find


Great Idea by the way can’t wait to get it working as it will be really usefull for A project of mine!

ah massive apologies - my gist cut the RGB array off at the end - fixed it now, should be working. There are 53 RGB tuples in the data