5
5
import displayio
6
6
import terminalio
7
7
from adafruit_display_text .label import Label
8
+ from simpleio import map_range
8
9
9
- number_of_colors = 64
10
+ number_of_colors = 64 # Number of color in the gradian
11
+ last_color = number_of_colors - 1 # Last color in palette
10
12
palette = displayio .Palette (number_of_colors ) # Palette with all our colors
11
13
12
14
## Heatmap code inspired from: http://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients
21
23
22
24
def MakeHeatMapColor ():
23
25
for c in range (number_of_colors ):
24
- value = c * (NUM_COLORS - 1 ) / ( number_of_colors - 1 )
26
+ value = c * (NUM_COLORS - 1 ) / last_color
25
27
idx1 = int (value ) # Our desired color will be after this index.
26
28
if idx1 == value : # This is the corner case
27
29
red = color [idx1 ][0 ]
@@ -58,8 +60,7 @@ def MakeHeatMapColor():
58
60
group = displayio .Group ()
59
61
60
62
min_label = Label (terminalio .FONT , max_glyphs = 10 , color = palette [0 ], x = 0 , y = 110 )
61
- max_label = Label (terminalio .FONT , max_glyphs = 10 , color = palette [number_of_colors - 1 ], \
62
- x = 80 , y = 110 )
63
+ max_label = Label (terminalio .FONT , max_glyphs = 10 , color = palette [last_color ], x = 80 , y = 110 )
63
64
64
65
# Add all the sub-group to the SuperGroup
65
66
group .append (image_group )
@@ -70,23 +71,8 @@ def MakeHeatMapColor():
70
71
# Add the SuperGroup to the Display
71
72
board .DISPLAY .show (group )
72
73
73
- mini = 0
74
- maxi = 0
75
-
76
- my_a1 = 20
77
- my_a2 = 37
78
-
79
- def temp2index (s , a1 , a2 ):
80
- b1 = 0
81
- b2 = number_of_colors - 1
82
-
83
- if s < a1 :
84
- r = b1
85
- elif s > a2 :
86
- r = b2
87
- else :
88
- r = int ( round ( b1 + ( (s - a1 ) * (b2 - b1 ) / (a2 - a1 ) ) ) )
89
- return r
74
+ min_t = 20 # Initial minimum temperature range, before auto scale
75
+ max_t = 37 # Initial maximum temperature range, before auto scale
90
76
91
77
i2c = busio .I2C (board .SCL , board .SDA , frequency = 800000 )
92
78
@@ -106,10 +92,11 @@ def temp2index(s, a1, a2):
106
92
except ValueError :
107
93
# these happen, no biggie - retry
108
94
continue
109
- print ("Read 2 frames in %0.2f s" % (time .monotonic ()- stamp ))
110
95
111
- mini = frame [0 ] # Define a default min and max value
112
- maxi = frame [0 ] # Will be updated by temp2index function
96
+ # print("Time for data aquisition: %0.2f s" % (time.monotonic()-stamp))
97
+
98
+ mini = frame [0 ] # Define a min temperature of current image
99
+ maxi = frame [0 ] # Define a max temperature of current image
113
100
114
101
for h in range (24 ):
115
102
for w in range (32 ):
@@ -118,13 +105,15 @@ def temp2index(s, a1, a2):
118
105
maxi = t
119
106
if t < mini :
120
107
mini = t
121
- image_bitmap [w , (23 - h )] = temp2index ( t , my_a1 , my_a2 )
108
+ image_bitmap [w , (23 - h )] = int ( map_range ( t , min_t , max_t , 0 , last_color ) )
122
109
123
- min_label .text = "%0.2f" % (my_a1 )
110
+ min_label .text = "%0.2f" % (min_t )
124
111
125
- max_string = "%0.2f" % (my_a2 )
112
+ max_string = "%0.2f" % (max_t )
126
113
max_label .x = 120 - (5 * len (max_string )) # Tricky calculation to left align
127
114
max_label .text = max_string
128
115
129
- my_a1 = mini # Automatically change the color scale
130
- my_a2 = maxi
116
+ min_t = mini # Automatically change the color scale
117
+ max_t = maxi
118
+ # print((mini, maxi)) # Use this line to display min and max graph in Mu
119
+ # print("Total time for aquisition and display %0.2f s" % (time.monotonic()-stamp))
0 commit comments