-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathvalue_to_rgb.py
executable file
·34 lines (18 loc) · 1.31 KB
/
value_to_rgb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding: utf-8
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), (0, 255, 92), (0, 255, 54), (0, 255, 16), (23, 255, 0), (62, 255, 0), (101, 255, 0), (138, 255, 0), (176, 255, 0), (215, 255, 0), (253, 255, 0), (255, 250, 0), (255, 240, 0), (255, 230, 0), (255, 220, 0), (255, 210, 0), (255, 200, 0), (255, 190, 0), (255, 180, 0), (255, 170, 0), (255, 160, 0), (255, 150, 0), (255, 140, 0), (255, 130, 0), (255, 120, 0), (255, 110, 0), (255, 100, 0), (255, 90, 0), (255, 80, 0), (255, 70, 0), (255, 60, 0), (255, 50, 0), (255, 40, 0), (255, 30, 0), (255, 20, 0), (255, 10, 0), (255, 0, 0), (255, 0, 16), (255, 0, 32), (255, 0, 48), (255, 0, 64)]
def temp_rgb(temp, min, max):
temp=int(temp)
if temp<min: temp=min
elif temp>max: temp=max
index = (((temp - min) * (53 - 0)) / (max - min)) + 0
output=rgb_array[index]
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__":
main()