File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030 # Clear the display frame buffer
3131 display .fill (0 )
3232
33- # Clamp distance to maximum range to avoid negative ratios
33+ # Clamp distance to maximum range and compute integer proximity
3434 clamped_dist = max (0 , min (distance , MAX_DISTANCE_MM ))
35+ proximity = MAX_DISTANCE_MM - clamped_dist
3536
36- # Calculate ratio (1.0 = extremely close, 0.0 = MAX_DISTANCE_MM or further)
37- ratio = 1.0 - (clamped_dist / MAX_DISTANCE_MM )
38-
39- # Map ratio to a maximum width of 80 pixels (to fit the round screen) and brightness (15 levels)
40- bar_width = int (80 * ratio )
41- brightness = int (15 * ratio )
37+ # Map proximity linearly to a maximum width of 80 pixels and brightness (15 levels) using integer math
38+ bar_width = (80 * proximity ) // MAX_DISTANCE_MM
39+ brightness = (15 * proximity ) // MAX_DISTANCE_MM
4240
4341 # If the object is within the detection range, ensure minimum visibility
44- if distance < MAX_DISTANCE_MM :
42+ if distance <= MAX_DISTANCE_MM :
4543 bar_width = max (1 , bar_width )
4644 brightness = max (1 , brightness )
4745
You can’t perform that action at this time.
0 commit comments