Skip to content

Commit 5bb485f

Browse files
authored
Update mlx90640_pygamer.py
Remove the use of global to compute mini and maxi. Require a1 and a2 as parameter and moving the min/max computation. Also b1=0 to use all the color.
1 parent 631b916 commit 5bb485f

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

examples/mlx90640_pygamer.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,15 @@ def MakeHeatMapColor():
7373
mini = 0
7474
maxi = 0
7575

76-
a1 = 20
77-
a2 = 37
76+
my_a1 = 20
77+
my_a2 = 37
7878

79-
def temp2index(s):
79+
def temp2index(s, a1, a2):
8080
global mini, maxi
81-
global a1, a2
8281

83-
b1 = 1
82+
b1 = 0
8483
b2 = number_of_colors - 1
8584

86-
if s > maxi:
87-
maxi = s
88-
if s < mini:
89-
mini = s
90-
9185
if s < a1:
9286
r = b1
9387
elif s > a2:
@@ -106,6 +100,7 @@ def temp2index(s):
106100
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_4_HZ
107101

108102
frame = [0] * 768
103+
109104
while True:
110105
stamp = time.monotonic()
111106
try:
@@ -121,13 +116,17 @@ def temp2index(s):
121116
for h in range(24):
122117
for w in range(32):
123118
t = frame[h*32 + w]
124-
image_bitmap[w, (23-h)] = temp2index(t) # Convert temperature to palette index
119+
if t > maxi:
120+
maxi = t
121+
if t < mini:
122+
mini = t
123+
image_bitmap[w, (23-h)] = temp2index(t, my_a1, my_a2)
125124

126-
min_label.text="%0.2f" % (mini)
125+
min_label.text="%0.2f" % (my_a1)
127126

128-
max_string="%0.2f" % (maxi)
127+
max_string="%0.2f" % (my_a2)
129128
max_label.x=120-(5*len(max_string)) # Tricky calculation to left align
130129
max_label.text=max_string
131130

132-
a1 = mini # Automatically change the color scale
133-
a2 = maxi
131+
my_a1 = mini # Automatically change the color scale
132+
my_a2 = maxi

0 commit comments

Comments
 (0)