Hi!
I've built a little controller for a PC-Casemod which controls an RGB-LED-Strip that change their color depending on the inner case temperature.
To get it to work I've used some P16NF06L N-Channel Power mosfets and an DS18S20 temperature sensor with the OneWire library.
So far, everything works perfect.
The only "issue" I have with the code is that for the color fade (from blue to red) I'm using a hard-coded array for the single values, which makes the code fairly big and somewhat hard to maintain.
What I'd like to do is to calculate an array so the resolution could be determined in a variable.
I just don't understand how I could implement this in the code since sometimes the values are constant and sometimes they change.
R G B
0 0 255 Blue
0 255 255 Teal
0 255 0 Green
255 255 0 Yellow
255 0 0 Red
This would be the min/max values to change the color specific to my needs.
And this are the arrays I've come up with that I calculated manually:
int C_RED[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255};
int C_GREEN[] = {0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 238, 221, 204, 187, 170, 153, 136, 119, 102, 85, 68, 51, 34, 17, 0};
int C_BLUE[] = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 238, 221, 204, 187, 170, 153, 136, 119, 102, 85, 68, 51, 34, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
As you can see, they are pretty big, I'd like to calculate them in the setup routine so I can determine the resolution.
I'd appreciate any help
Full code in the attachment.
Thanks in advance.
Andy
inframe_led_temp.ino (2.7 KB)