Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples not using full color pallete (with solution) #17

Open
MickTheMechanic opened this issue Dec 21, 2020 · 3 comments
Open

Examples not using full color pallete (with solution) #17

MickTheMechanic opened this issue Dec 21, 2020 · 3 comments

Comments

@MickTheMechanic
Copy link

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);

@ladyada
Copy link
Member

ladyada commented Dec 21, 2020

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

@MickTheMechanic
Copy link
Author

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

@caternuson
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants