adafruit/Adafruit_AMG88xx

Examples not using full color pallete (with solution)

Opened this issue · 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.

Standard example:

//original code
for(int i=0; i<AMG88xx_PIXEL_ARRAY_SIZE; i++){
    uint8_t colorIndex = map(pixels[i], MINTEMP, MAXTEMP, 0, 255);
    colorIndex = constrain(colorIndex, 0, 255);

//New code
for(int i=0; i<AMG88xx_PIXEL_ARRAY_SIZE; i++){
    uint8_t colorIndex = map(pixels[i] * 100, MINTEMP * 100, MAXTEMP * 100, 0, 255);
    colorIndex = constrain(colorIndex, 0, 255);

Interpolation example:


uint8_t colorIndex = map(colorTemp, MINTEMP, MAXTEMP, 0, 255);
      colorIndex = constrain(colorIndex, 0, 255);


uint8_t colorIndex = map(colorTemp * 100, MINTEMP * 100, MAXTEMP * 100, 0, 255);
      colorIndex = constrain(colorIndex, 0, 255);

hihi, could you submit a PR, then we could test your updates :)

I have just submitted a PR. Its my first time, I hope I did it correctly

The PR is #18. Just adding the reference here for tie in.