Adafruit_AMG88xx icon indicating copy to clipboard operation
Adafruit_AMG88xx copied to clipboard

Fix examples to make use of all colors in array.

Open MickTheMechanic opened this issue 4 years ago • 3 comments

The examples provided do not make use of all available 255 colors in the array.

This is because the map () function converts pixels[] to an int, resulting in a different color for every full degree shown on screen. The result is the absolute maximum number of differet colors that can be shown on screen at any one time is the difference between MAXTEMP and MINTEMP in whole numbers (for example, if MINTEMP= 25 and MAXTEMP = 35, only 10 different colors from the array can be used at any one time).

Solution

The solution is very simple, inside the map() function, multiply pixels[], mintemp, and maxtemp by 100, this moves the decimal point of the float 2 places to the right. The resulting whole number is then mapped to colorIndex, which will result in the full color array being used.

MickTheMechanic avatar Dec 21 '20 18:12 MickTheMechanic

Please note, multiplying by 1000 works much better than 100.

I am unsure how these changes affect performance for different MCU’s, I am using an ESP32 for testing purposes.

MickTheMechanic avatar Dec 22 '20 08:12 MickTheMechanic

Sorry for missing this PR. Seems like a nice update to the examples. If you're still up for working this, suggest creating a #def for the value. Could call it something like SCALE. For example, near top of sketch:

#define SCALE 100

and then later:

     uint8_t colorIndex = map(pixels[i] * SCALE, MINTEMP * SCALE, MAXTEMP * SCALE, 0, 255); //move decimal point of pixels[] two places to the right, otherwise colors are only mapped to full degrees and not points.

caternuson avatar May 12 '22 18:05 caternuson

Or...would it work to compute the SCALE value? The output range is known = 255. So just need to scale the set temperature range up to that based on min and max:

#define MINTEMP 22
#define MAXTEMP 34
#define SCALETEMP (255 /(MAXTEMP - MINTEMP))

caternuson avatar May 12 '22 19:05 caternuson