// // Some C code I used to generate the values->colors map. I didn't run this code on the Arduino. I used ideone.com // and then pasted the output into my arduino code. #include <iostream> #include <stdint.h> #include <math.h> using namespace std; const int numValues = 64; // number of colors in our output array. This should correspond // to the max value you want to display. double breakPoint = log10(numValues)/2.0; // // Blend two colors together based on the ratio. ratio of 0.0 will be 100% color a and // ratio of 1.0 will be 100% color b. uint32_t blend (uint32_t ina, uint32_t inb, double ratio) { int r = (((ina >> 16) & 0xff) * (1.0-ratio)) + (((inb >> 16) & 0xff) * ratio); int g = (((ina >> 8) & 0xff) * (1.0-ratio)) + (((inb >> 8) & 0xff) * ratio); int b = (((ina >> 0) & 0xff) * (1.0-ratio)) + (((inb >> 0) & 0xff) * ratio); return ((r << 16) | (g << 8) | b); } // // Scale the intensity of the passed in color. I am using max brightness colors and // 0.0 - 1.0 as the scale value. uint32_t scale (uint32_t ina, double scale_value) { int r = ((ina >> 16) & 0xff) * scale_value; int g = ((ina >> 8) & 0xff) * scale_value; int b = ((ina >> 0) & 0xff) * scale_value; return ((r << 16) | (g << 8) | b); } // // Fade blue -> green -> red. I've built in a logarithmic response to make it more of a // dB meter. int main() { for (int i = 1; i <= numValues; i++) { double logValue = log10(i); double scaleValue = log10(i+2) / log10(numValues+2); double ratio = (logValue < breakPoint) ? logValue / breakPoint : (logValue - breakPoint) / breakPoint; uint32_t color = 0; if (logValue < breakPoint) color = blend (0x0000ff, 0x00ff00, ratio); else color = blend (0x00ff00, 0xff0000, ratio); color = scale (color, scaleValue); cout << "0x" << hex << color << ", "; } return 0; }
Standard input is empty
0x42, 0x1c37, 0x332e, 0x4823, 0x5b1a, 0x6c11, 0x7c08, 0x8c00, 0x88900, 0x108600, 0x178300, 0x1e8100, 0x267e00, 0x2d7b00, 0x347700, 0x3a7400, 0x407100, 0x466e00, 0x4d6b00, 0x526800, 0x586500, 0x5e6200, 0x636000, 0x685d00, 0x6d5a00, 0x725700, 0x775400, 0x7c5100, 0x804f00, 0x864c00, 0x8a4900, 0x8f4600, 0x924400, 0x974100, 0x9b3f00, 0x9f3c00, 0xa33a00, 0xa83700, 0xab3500, 0xaf3200, 0xb33000, 0xb72e00, 0xbb2b00, 0xbe2900, 0xc12700, 0xc52400, 0xc92200, 0xcc2000, 0xd01e00, 0xd31c00, 0xd71900, 0xda1700, 0xdc1500, 0xe01300, 0xe31100, 0xe60f00, 0xe90d00, 0xec0b00, 0xf00800, 0xf30600, 0xf60400, 0xf90200, 0xfc0000, 0xff0000,