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

Fix examples to make use of all colors in array. #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

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.

Add fix to make use of all 255 colors in array
Add fix to make use of all 255 colors
Add fix to use all 255 colors in array
@MickTheMechanic
Copy link
Author

MickTheMechanic commented Dec 22, 2020

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.

@caternuson
Copy link
Contributor

caternuson commented May 12, 2022

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
Copy link
Contributor

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

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

Successfully merging this pull request may close these issues.

2 participants