Skip to content

Commit 0ee7b6f

Browse files
authored
Merge pull request #7 from dglaude/patch-1
Update mlx90640_pygamer.py
2 parents 2021b9d + fb926e8 commit 0ee7b6f

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

examples/mlx90640_pygamer.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import displayio
66
import terminalio
77
from adafruit_display_text.label import Label
8+
from simpleio import map_range
89

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
1012
palette = displayio.Palette(number_of_colors) # Palette with all our colors
1113

1214
## Heatmap code inspired from: http://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients
@@ -21,7 +23,7 @@
2123

2224
def MakeHeatMapColor():
2325
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
2527
idx1 = int(value) # Our desired color will be after this index.
2628
if idx1 == value : # This is the corner case
2729
red = color[idx1][0]
@@ -58,8 +60,7 @@ def MakeHeatMapColor():
5860
group = displayio.Group()
5961

6062
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)
6364

6465
# Add all the sub-group to the SuperGroup
6566
group.append(image_group)
@@ -70,23 +71,8 @@ def MakeHeatMapColor():
7071
# Add the SuperGroup to the Display
7172
board.DISPLAY.show(group)
7273

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
9076

9177
i2c = busio.I2C(board.SCL, board.SDA, frequency=800000)
9278

@@ -106,10 +92,11 @@ def temp2index(s, a1, a2):
10692
except ValueError:
10793
# these happen, no biggie - retry
10894
continue
109-
print("Read 2 frames in %0.2f s" % (time.monotonic()-stamp))
11095

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
113100

114101
for h in range(24):
115102
for w in range(32):
@@ -118,13 +105,15 @@ def temp2index(s, a1, a2):
118105
maxi = t
119106
if t < mini:
120107
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 ))
122109

123-
min_label.text="%0.2f" % (my_a1)
110+
min_label.text="%0.2f" % (min_t)
124111

125-
max_string="%0.2f" % (my_a2)
112+
max_string="%0.2f" % (max_t)
126113
max_label.x=120-(5*len(max_string)) # Tricky calculation to left align
127114
max_label.text=max_string
128115

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

Comments
 (0)