需要帮助从 12 字节生成新的 24 字节 RGB 查找数组,或更好的编码方式
Need help generating new 24 byte RGB lookup array from 12 byte, or a better way to code this
我使用 4 个 RGB LED 作为发动机参数的指示器。 "My" 代码通过从 500 个条目数组中查找 12 个字节来工作,引擎参数被缩放到。 0 RPM = 1 个蓝色 LED,7000 RPM = 4 个红色 LED。在 3500 RPM 时,下方两个 LED 呈绿色。我通过 oled 显示器和编码器有配置菜单来设置这些 low/center/high 值和 save/load 它们来自 eeprom。通过这种方式,我可以使用一个 LED RGB 阵列来显示许多操作参数,所有这些参数的比例都略有不同。
我正在使用更小的 LED 制作一个新的 LED 环形板,这样我就可以在 space 4 个之前安装 8 个 LED,以获得更好的分辨率。我想扩展,或者最好找出我拥有的这个数组是如何生成的,这样我就可以尝试不同的东西。当前数组是 500 个 12 位条目,我想将其重新缩放或重写为 1024 个 24 位条目。
当我说 "my" 代码时,我的意思是我正在使用我在 Internet 上找到的一段代码。我已经完成并重写了,或者至少弄清楚了每一位都在做什么,但我仍然无法确定这个数组是在 excel 中以某种方式生成的,还是手工编码的。
http://www.msextra.com/forums/viewtopic.php?f=67&t=52539
我使用更大的显示器制作了新硬件,并在此处重写了大部分代码...
https://github.com/deezums/TeensyMS
相关部分在TeensyMS/Code/_171_LED_INIT.ino和TeensyMS/blob/master/Code/_371_LED_LOOP.ino
您可以在此视频中了解 LED 的工作原理 1:10
https://www.youtube.com/watch?v=5pkusOi-U0U&feature=youtu.be
我 am/plan 使用 SAMD54,所以我应该有足够的存储空间 space。
struct ledval {
byte r0;
byte g0;
byte b0;
byte r1;
byte g1;
byte b1;
byte r2;
byte g2;
byte b2;
byte r3;
byte g3;
byte b3;
};
const ledval ledarray[] PROGMEM = {
//r0, g0, b0, r1, g1, b1, r2, g2, b2, r3, g3, b3
{0x0,0x5,0xFF,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //0
{0x0,0x6,0xFE,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //1
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,0x0,0x0,0x1,0x0}, //258
{0xE,0xF6,0x0,0x3,0x42,0x0,0x1,0x11,0x0,0x0,0x1,0x0}, //259
{0xF,0xF5,0x0,0x4,0x42,0x0,0x1,0x11,0x0,0x0,0x1,0x0}, //260
{0x10,0xF4,0x0,0x4,0x42,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //261
{0x11,0xF3,0x0,0x4,0x42,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //262
{0x12,0xF2,0x0,0x4,0x42,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //263
{0x13,0xF1,0x0,0x5,0x43,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //264
{0x14,0xF0,0x0,0x5,0x43,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //265
{0x15,0xEF,0x0,0x5,0x43,0x0,0x1,0x13,0x0,0x0,0x1,0x0}, //266
{0x16,0xEE,0x0,0x6,0x43,0x0,0x1,0x13,0x0,0x0,0x1,0x0}, //267
{0x17,0xED,0x0,0x6,0x44,0x0,0x1,0x13,0x0,0x0,0x1,0x0}, //268
.....
{0xF0,0x14,0x0,0xE1,0x12,0x0,0xD4,0x11,0x0,0xBC,0xF,0x0}, //485
{0xF1,0x13,0x0,0xE3,0x11,0x0,0xD7,0x10,0x0,0xC0,0xF,0x0}, //486
{0xF2,0x12,0x0,0xE5,0x11,0x0,0xD9,0x10,0x0,0xC4,0xE,0x0}, //487
{0xF3,0x11,0x0,0xE7,0x10,0x0,0xDC,0xF,0x0,0xC8,0xD,0x0}, //488
{0xF4,0x10,0x0,0xE9,0xF,0x0,0xDF,0xE,0x0,0xCC,0xD,0x0}, //489
{0xF5,0xF,0x0,0xEB,0xE,0x0,0xE1,0xD,0x0,0xD0,0xC,0x0}, //490
{0xF6,0xE,0x0,0xED,0xD,0x0,0xE4,0xD,0x0,0xD4,0xC,0x0}, //491
{0xF7,0xD,0x0,0xEF,0xC,0x0,0xE7,0xC,0x0,0xD9,0xB,0x0}, //492
{0xF8,0xC,0x0,0xF1,0xB,0x0,0xEA,0xB,0x0,0xDD,0xA,0x0}, //493
{0xF9,0xB,0x0,0xF3,0xA,0x0,0xED,0xA,0x0,0xE2,0x9,0x0}, //494
{0xFA,0xA,0x0,0xF5,0x9,0x0,0xF0,0x9,0x0,0xE6,0x9,0x0}, //495
{0xFB,0x9,0x0,0xF7,0x8,0x0,0xF3,0x8,0x0,0xEB,0x8,0x0}, //496
{0xFC,0x8,0x0,0xF8,0x7,0x0,0xF6,0x7,0x0,0xF0,0x7,0x0}, //497
{0xFD,0x7,0x0,0xFA,0x6,0x0,0xF8,0x6,0x0,0xF5,0x6,0x0}, //498
{0xFE,0x6,0x0,0xFC,0x5,0x0,0xFB,0x5,0x0,0xF9,0x5,0x0}, //499
{0xFF,0x5,0x0,0xFC,0x5,0x0,0xFB,0x5,0x0,0x28,0x8,0x0} //500
};
整个 LED 阵列都在这里...
https://github.com/deezums/TeensyMS/blob/master/Code/_171_LED_INIT.ino#L93
谢谢!
最好在您的代码中实现一个生成 4 个 RGB 值的函数,而不是对查找进行硬编码 table。我相信 table 无论如何都是使用这样的函数生成的,所以如果你真的需要预先计算它们,你可以只保存它的所有输出。
// Generates an RGB color between Red and Green based on the given value (V).
void LerpRGB(const uint8_t V, uint8_t& R, uint8_t& G, uint8_t& B)
{
R = V;
G = 255 - V;
B = 0;
}
// Takes a normalized value between 0 (min incl.) and 1024 (max excl.) and
// an array of 12 bytes to store the output of the 4 RGB LED colors.
void CalcLEDs(int value, uint8_t* ledValues)
{
// Set all 12 bytes to 0
for (int i = 0; i < 12; i++)
{
ledValues[i] = 0x00;
}
// Set first LED to blue and exit if value is 0
if (value == 0)
{
ledValues[2] = 0xFF;
return;
}
// For 4 LEDs...
for (int i = 0; i < 4; i++)
{
// Get some handy references to the RGB components
uint8_t& r = ledValues[i * 3 + 0];
uint8_t& g = ledValues[i * 3 + 1];
uint8_t& b = ledValues[i * 3 + 2];
// Calculate the domain for the current LED
int lerpStart = 256 * i;
int lerpStop = 256 * (i + 1);
// Clamp the value if it is outside the domain, otherwise lerp between green and red
if (value < lerpStart)
g = 0xFF;
else if (value >= lerpStop)
r = 0xFF;
else
LerpRGB(value - lerpStart, r, g, b);
}
}
然后你可以像这样使用这个函数...
uint8_t* ledVals = new uint8_t[12];
CalcLEDs(your_operational_value, ledVals);
// Do something with ledVals...
delete[] ledVals
CalcLEDs
函数采用 [0, 1023]
范围内的输入,因为这简化了数学运算。我还确保这里没有使用浮点类型,因为你板上的 CPU 有一个可选的 FPU。您也可以将 uint8_t
替换为您正在使用的任何字节类型。
我设法用一些异常混乱的代码得到了一个新数组。这从 0-1024 从一个蓝色 LED 变为 8 个红色 LED,在中间点亮所有颜色。 512 在一半的 LED 上呈纯绿色。大约每满刻度的 1/7,新的 LED 就会开始变暗。
这是生成 table 的代码,我对这些东西很愚蠢所以请原谅这是一个完整的火车残骸。在我的辩护中,它有效!我不可能填满 T3.6 或 SAMD51,所以我什至不觉得这样浪费 space 有那么糟糕。
谢谢大家的帮助!
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < 1025; i++ )
{
uint8_t* ledVals = new uint8_t[3];
CalcLEDs(i, ledVals);
Serial.print("{");
for (int j = 0; j < 24; j++)
{
Serial. print("0x");
Serial.print(ledVals[j], HEX);
if (j < 23)
{
Serial.print(",");
}
}
Serial.print("}, // ");
Serial.println(i);
delete[] ledVals;
}
delay (10000);
}
void CalcLEDs(int value, uint8_t* ledValues)
{
// Set all 24 bytes to 0
for (int i = 0; i < 24; i++)
{
ledValues[i] = 0x00;
}
// For 4 LEDs...
for (int i = 0; i < 8; i++)
{
// Get some handy references to the RGB components
uint8_t& r = ledValues[i * 3 + 0];
uint8_t& g = ledValues[i * 3 + 1];
uint8_t& b = ledValues[i * 3 + 2];
// Calculate the current color
if (value < 257) // less than 1/4 blue fade to green
{
uint8_t blue = map(value,0, 256, 255, 127); //if value is zero, blue should be max, if value is max, blue should be half
uint8_t green = map(value, 0, 256, 0, 128); //if value is zero, green is zero, if value is max, green is half
g = green;
b = blue;
r = 0;
} else if (value < 513)
{
uint8_t blue = map(value, 256, 512, 128, 0);
uint8_t green = map(value, 256, 512, 127, 255);
g = green;
b = blue;
r = 0;
} else if (value < 769)
{
uint8_t green = map(value, 512, 768, 255, 127);
uint8_t red = map(value, 512, 768, 0, 128);
r = red;
g = green;
b = 0;
} else if (value < 1025)
{
uint8_t green = map(value, 768, 1024, 128, 0);
uint8_t red = map(value, 768, 1024, 127, 255);
r = red;
g = green;
b = 0;
}
}
if (value > 895)
{
int temp = 2 *(1024 - value);
uint8_t& r = ledValues[7 * 3 + 0];
uint8_t& g = ledValues[7 * 3 + 1];
uint8_t& b = ledValues[7 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
} else if (value > 767)
{
int temp = 2 * (896 - value);
uint8_t& r = ledValues[6 * 3 + 0];
uint8_t& g = ledValues[6 * 3 + 1];
uint8_t& b = ledValues[6 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[7 * 3 + 0];
uint8_t& g1 = ledValues[7 * 3 + 1];
uint8_t& b1 = ledValues[7 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
} else if (value > 639)
{
int temp = 2 * (768 - value);
uint8_t& r = ledValues[5 * 3 + 0];
uint8_t& g = ledValues[5 * 3 + 1];
uint8_t& b = ledValues[5 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[6 * 3 + 0];
uint8_t& g1 = ledValues[6 * 3 + 1];
uint8_t& b1 = ledValues[6 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[7 * 3 + 0];
uint8_t& g2 = ledValues[7 * 3 + 1];
uint8_t& b2 = ledValues[7 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
} else if (value > 511)
{
int temp = 2 * (640 - value);
uint8_t& r = ledValues[4 * 3 + 0];
uint8_t& g = ledValues[4 * 3 + 1];
uint8_t& b = ledValues[4 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[5 * 3 + 0];
uint8_t& g1 = ledValues[5 * 3 + 1];
uint8_t& b1 = ledValues[5 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[6 * 3 + 0];
uint8_t& g2 = ledValues[6 * 3 + 1];
uint8_t& b2 = ledValues[6 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[7 * 3 + 0];
uint8_t& g3 = ledValues[7 * 3 + 1];
uint8_t& b3 = ledValues[7 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
} else if (value > 383)
{
int temp = 2 * (512 - value);
uint8_t& r = ledValues[3 * 3 + 0];
uint8_t& g = ledValues[3 * 3 + 1];
uint8_t& b = ledValues[3 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[4 * 3 + 0];
uint8_t& g1 = ledValues[4 * 3 + 1];
uint8_t& b1 = ledValues[4 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[5 * 3 + 0];
uint8_t& g2 = ledValues[5 * 3 + 1];
uint8_t& b2 = ledValues[5 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[6 * 3 + 0];
uint8_t& g3 = ledValues[6 * 3 + 1];
uint8_t& b3 = ledValues[6 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
uint8_t& r4 = ledValues[7 * 3 + 0];
uint8_t& g4 = ledValues[7 * 3 + 1];
uint8_t& b4 = ledValues[7 * 3 + 2];
r4 = 0;
g4 = 0;
b4 = 0;
} else if (value > 255)
{
int temp = 2 * (384 - value);
uint8_t& r = ledValues[2 * 3 + 0];
uint8_t& g = ledValues[2 * 3 + 1];
uint8_t& b = ledValues[2 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[3 * 3 + 0];
uint8_t& g1 = ledValues[3 * 3 + 1];
uint8_t& b1 = ledValues[3 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[4 * 3 + 0];
uint8_t& g2 = ledValues[4 * 3 + 1];
uint8_t& b2 = ledValues[4 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[5 * 3 + 0];
uint8_t& g3 = ledValues[5 * 3 + 1];
uint8_t& b3 = ledValues[5 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
uint8_t& r4 = ledValues[6 * 3 + 0];
uint8_t& g4 = ledValues[6 * 3 + 1];
uint8_t& b4 = ledValues[6 * 3 + 2];
r4 = 0;
g4 = 0;
b4 = 0;
uint8_t& r5 = ledValues[7 * 3 + 0];
uint8_t& g5 = ledValues[7 * 3 + 1];
uint8_t& b5 = ledValues[7 * 3 + 2];
r5 = 0;
g5 = 0;
b5 = 0;
} else if (value > 127)
{
int temp = 2 * (256 - value);
uint8_t& r = ledValues[1 * 3 + 0];
uint8_t& g = ledValues[1 * 3 + 1];
uint8_t& b = ledValues[1 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[2 * 3 + 0];
uint8_t& g1 = ledValues[2 * 3 + 1];
uint8_t& b1 = ledValues[2 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[3 * 3 + 0];
uint8_t& g2 = ledValues[3 * 3 + 1];
uint8_t& b2 = ledValues[3 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[4 * 3 + 0];
uint8_t& g3 = ledValues[4 * 3 + 1];
uint8_t& b3 = ledValues[4 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
uint8_t& r4 = ledValues[5 * 3 + 0];
uint8_t& g4 = ledValues[5 * 3 + 1];
uint8_t& b4 = ledValues[5 * 3 + 2];
r4 = 0;
g4 = 0;
b4 = 0;
uint8_t& r5 = ledValues[6 * 3 + 0];
uint8_t& g5 = ledValues[6 * 3 + 1];
uint8_t& b5 = ledValues[6 * 3 + 2];
r5 = 0;
g5 = 0;
b5 = 0;
uint8_t& r6 = ledValues[7 * 3 + 0];
uint8_t& g6 = ledValues[7 * 3 + 1];
uint8_t& b6 = ledValues[7 * 3 + 2];
r6 = 0;
g6 = 0;
b6 = 0;
} else if (value < 128)
{
int temp = 2 * (256 - value);
uint8_t& r = ledValues[1 * 3 + 0];
uint8_t& g = ledValues[1 * 3 + 1];
uint8_t& b = ledValues[1 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[2 * 3 + 0];
uint8_t& g1 = ledValues[2 * 3 + 1];
uint8_t& b1 = ledValues[2 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[3 * 3 + 0];
uint8_t& g2 = ledValues[3 * 3 + 1];
uint8_t& b2 = ledValues[3 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[4 * 3 + 0];
uint8_t& g3 = ledValues[4 * 3 + 1];
uint8_t& b3 = ledValues[4 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
uint8_t& r4 = ledValues[5 * 3 + 0];
uint8_t& g4 = ledValues[5 * 3 + 1];
uint8_t& b4 = ledValues[5 * 3 + 2];
r4 = 0;
g4 = 0;
b4 = 0;
uint8_t& r5 = ledValues[6 * 3 + 0];
uint8_t& g5 = ledValues[6 * 3 + 1];
uint8_t& b5 = ledValues[6 * 3 + 2];
r5 = 0;
g5 = 0;
b5 = 0;
uint8_t& r6 = ledValues[7 * 3 + 0];
uint8_t& g6 = ledValues[7 * 3 + 1];
uint8_t& b6 = ledValues[7 * 3 + 2];
r6 = 0;
g6 = 0;
b6 = 0;
}
}
我使用 4 个 RGB LED 作为发动机参数的指示器。 "My" 代码通过从 500 个条目数组中查找 12 个字节来工作,引擎参数被缩放到。 0 RPM = 1 个蓝色 LED,7000 RPM = 4 个红色 LED。在 3500 RPM 时,下方两个 LED 呈绿色。我通过 oled 显示器和编码器有配置菜单来设置这些 low/center/high 值和 save/load 它们来自 eeprom。通过这种方式,我可以使用一个 LED RGB 阵列来显示许多操作参数,所有这些参数的比例都略有不同。
我正在使用更小的 LED 制作一个新的 LED 环形板,这样我就可以在 space 4 个之前安装 8 个 LED,以获得更好的分辨率。我想扩展,或者最好找出我拥有的这个数组是如何生成的,这样我就可以尝试不同的东西。当前数组是 500 个 12 位条目,我想将其重新缩放或重写为 1024 个 24 位条目。
当我说 "my" 代码时,我的意思是我正在使用我在 Internet 上找到的一段代码。我已经完成并重写了,或者至少弄清楚了每一位都在做什么,但我仍然无法确定这个数组是在 excel 中以某种方式生成的,还是手工编码的。
http://www.msextra.com/forums/viewtopic.php?f=67&t=52539
我使用更大的显示器制作了新硬件,并在此处重写了大部分代码...
https://github.com/deezums/TeensyMS
相关部分在TeensyMS/Code/_171_LED_INIT.ino和TeensyMS/blob/master/Code/_371_LED_LOOP.ino
您可以在此视频中了解 LED 的工作原理 1:10 https://www.youtube.com/watch?v=5pkusOi-U0U&feature=youtu.be
我 am/plan 使用 SAMD54,所以我应该有足够的存储空间 space。
struct ledval {
byte r0;
byte g0;
byte b0;
byte r1;
byte g1;
byte b1;
byte r2;
byte g2;
byte b2;
byte r3;
byte g3;
byte b3;
};
const ledval ledarray[] PROGMEM = {
//r0, g0, b0, r1, g1, b1, r2, g2, b2, r3, g3, b3
{0x0,0x5,0xFF,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //0
{0x0,0x6,0xFE,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //1
{0x0,0x7,0xFD,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //2
{0x0,0x8,0xFC,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //3
{0x0,0x9,0xFB,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //4
{0x0,0xA,0xFA,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //5
{0x0,0xB,0xF9,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //6
{0x0,0xC,0xF8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //7
{0x0,0xD,0xF7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //8
{0x0,0xE,0xF6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //9
{0x0,0xF,0xF5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //10
{0x0,0x10,0xF4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //11
{0x0,0x11,0xF3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //12
{0x0,0x12,0xF2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}, //13
{0x0,0x13,0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,0x0}, //251
{0x7,0xFD,0x3,0x1,0x40,0x0,0x0,0x10,0x0,0x0,0x1,0x0}, //252
{0x8,0xFC,0x2,0x2,0x40,0x0,0x0,0x10,0x0,0x0,0x1,0x0}, //253
{0x9,0xFB,0x1,0x2,0x40,0x0,0x0,0x10,0x0,0x0,0x1,0x0}, //254
{0xA,0xFA,0x0,0x2,0x41,0x0,0x0,0x10,0x0,0x0,0x1,0x0}, //255
{0xB,0xF9,0x0,0x2,0x41,0x0,0x0,0x11,0x0,0x0,0x1,0x0}, //256
{0xC,0xF8,0x0,0x3,0x41,0x0,0x0,0x11,0x0,0x0,0x1,0x0}, //257
{0xD,0xF7,0x0,0x3,0x41,0x0,0x0,0x11,0x0,0x0,0x1,0x0}, //258
{0xE,0xF6,0x0,0x3,0x42,0x0,0x1,0x11,0x0,0x0,0x1,0x0}, //259
{0xF,0xF5,0x0,0x4,0x42,0x0,0x1,0x11,0x0,0x0,0x1,0x0}, //260
{0x10,0xF4,0x0,0x4,0x42,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //261
{0x11,0xF3,0x0,0x4,0x42,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //262
{0x12,0xF2,0x0,0x4,0x42,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //263
{0x13,0xF1,0x0,0x5,0x43,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //264
{0x14,0xF0,0x0,0x5,0x43,0x0,0x1,0x12,0x0,0x0,0x1,0x0}, //265
{0x15,0xEF,0x0,0x5,0x43,0x0,0x1,0x13,0x0,0x0,0x1,0x0}, //266
{0x16,0xEE,0x0,0x6,0x43,0x0,0x1,0x13,0x0,0x0,0x1,0x0}, //267
{0x17,0xED,0x0,0x6,0x44,0x0,0x1,0x13,0x0,0x0,0x1,0x0}, //268
.....
{0xF0,0x14,0x0,0xE1,0x12,0x0,0xD4,0x11,0x0,0xBC,0xF,0x0}, //485
{0xF1,0x13,0x0,0xE3,0x11,0x0,0xD7,0x10,0x0,0xC0,0xF,0x0}, //486
{0xF2,0x12,0x0,0xE5,0x11,0x0,0xD9,0x10,0x0,0xC4,0xE,0x0}, //487
{0xF3,0x11,0x0,0xE7,0x10,0x0,0xDC,0xF,0x0,0xC8,0xD,0x0}, //488
{0xF4,0x10,0x0,0xE9,0xF,0x0,0xDF,0xE,0x0,0xCC,0xD,0x0}, //489
{0xF5,0xF,0x0,0xEB,0xE,0x0,0xE1,0xD,0x0,0xD0,0xC,0x0}, //490
{0xF6,0xE,0x0,0xED,0xD,0x0,0xE4,0xD,0x0,0xD4,0xC,0x0}, //491
{0xF7,0xD,0x0,0xEF,0xC,0x0,0xE7,0xC,0x0,0xD9,0xB,0x0}, //492
{0xF8,0xC,0x0,0xF1,0xB,0x0,0xEA,0xB,0x0,0xDD,0xA,0x0}, //493
{0xF9,0xB,0x0,0xF3,0xA,0x0,0xED,0xA,0x0,0xE2,0x9,0x0}, //494
{0xFA,0xA,0x0,0xF5,0x9,0x0,0xF0,0x9,0x0,0xE6,0x9,0x0}, //495
{0xFB,0x9,0x0,0xF7,0x8,0x0,0xF3,0x8,0x0,0xEB,0x8,0x0}, //496
{0xFC,0x8,0x0,0xF8,0x7,0x0,0xF6,0x7,0x0,0xF0,0x7,0x0}, //497
{0xFD,0x7,0x0,0xFA,0x6,0x0,0xF8,0x6,0x0,0xF5,0x6,0x0}, //498
{0xFE,0x6,0x0,0xFC,0x5,0x0,0xFB,0x5,0x0,0xF9,0x5,0x0}, //499
{0xFF,0x5,0x0,0xFC,0x5,0x0,0xFB,0x5,0x0,0x28,0x8,0x0} //500
};
整个 LED 阵列都在这里... https://github.com/deezums/TeensyMS/blob/master/Code/_171_LED_INIT.ino#L93
谢谢!
最好在您的代码中实现一个生成 4 个 RGB 值的函数,而不是对查找进行硬编码 table。我相信 table 无论如何都是使用这样的函数生成的,所以如果你真的需要预先计算它们,你可以只保存它的所有输出。
// Generates an RGB color between Red and Green based on the given value (V).
void LerpRGB(const uint8_t V, uint8_t& R, uint8_t& G, uint8_t& B)
{
R = V;
G = 255 - V;
B = 0;
}
// Takes a normalized value between 0 (min incl.) and 1024 (max excl.) and
// an array of 12 bytes to store the output of the 4 RGB LED colors.
void CalcLEDs(int value, uint8_t* ledValues)
{
// Set all 12 bytes to 0
for (int i = 0; i < 12; i++)
{
ledValues[i] = 0x00;
}
// Set first LED to blue and exit if value is 0
if (value == 0)
{
ledValues[2] = 0xFF;
return;
}
// For 4 LEDs...
for (int i = 0; i < 4; i++)
{
// Get some handy references to the RGB components
uint8_t& r = ledValues[i * 3 + 0];
uint8_t& g = ledValues[i * 3 + 1];
uint8_t& b = ledValues[i * 3 + 2];
// Calculate the domain for the current LED
int lerpStart = 256 * i;
int lerpStop = 256 * (i + 1);
// Clamp the value if it is outside the domain, otherwise lerp between green and red
if (value < lerpStart)
g = 0xFF;
else if (value >= lerpStop)
r = 0xFF;
else
LerpRGB(value - lerpStart, r, g, b);
}
}
然后你可以像这样使用这个函数...
uint8_t* ledVals = new uint8_t[12];
CalcLEDs(your_operational_value, ledVals);
// Do something with ledVals...
delete[] ledVals
CalcLEDs
函数采用 [0, 1023]
范围内的输入,因为这简化了数学运算。我还确保这里没有使用浮点类型,因为你板上的 CPU 有一个可选的 FPU。您也可以将 uint8_t
替换为您正在使用的任何字节类型。
我设法用一些异常混乱的代码得到了一个新数组。这从 0-1024 从一个蓝色 LED 变为 8 个红色 LED,在中间点亮所有颜色。 512 在一半的 LED 上呈纯绿色。大约每满刻度的 1/7,新的 LED 就会开始变暗。
这是生成 table 的代码,我对这些东西很愚蠢所以请原谅这是一个完整的火车残骸。在我的辩护中,它有效!我不可能填满 T3.6 或 SAMD51,所以我什至不觉得这样浪费 space 有那么糟糕。
谢谢大家的帮助!
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < 1025; i++ )
{
uint8_t* ledVals = new uint8_t[3];
CalcLEDs(i, ledVals);
Serial.print("{");
for (int j = 0; j < 24; j++)
{
Serial. print("0x");
Serial.print(ledVals[j], HEX);
if (j < 23)
{
Serial.print(",");
}
}
Serial.print("}, // ");
Serial.println(i);
delete[] ledVals;
}
delay (10000);
}
void CalcLEDs(int value, uint8_t* ledValues)
{
// Set all 24 bytes to 0
for (int i = 0; i < 24; i++)
{
ledValues[i] = 0x00;
}
// For 4 LEDs...
for (int i = 0; i < 8; i++)
{
// Get some handy references to the RGB components
uint8_t& r = ledValues[i * 3 + 0];
uint8_t& g = ledValues[i * 3 + 1];
uint8_t& b = ledValues[i * 3 + 2];
// Calculate the current color
if (value < 257) // less than 1/4 blue fade to green
{
uint8_t blue = map(value,0, 256, 255, 127); //if value is zero, blue should be max, if value is max, blue should be half
uint8_t green = map(value, 0, 256, 0, 128); //if value is zero, green is zero, if value is max, green is half
g = green;
b = blue;
r = 0;
} else if (value < 513)
{
uint8_t blue = map(value, 256, 512, 128, 0);
uint8_t green = map(value, 256, 512, 127, 255);
g = green;
b = blue;
r = 0;
} else if (value < 769)
{
uint8_t green = map(value, 512, 768, 255, 127);
uint8_t red = map(value, 512, 768, 0, 128);
r = red;
g = green;
b = 0;
} else if (value < 1025)
{
uint8_t green = map(value, 768, 1024, 128, 0);
uint8_t red = map(value, 768, 1024, 127, 255);
r = red;
g = green;
b = 0;
}
}
if (value > 895)
{
int temp = 2 *(1024 - value);
uint8_t& r = ledValues[7 * 3 + 0];
uint8_t& g = ledValues[7 * 3 + 1];
uint8_t& b = ledValues[7 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
} else if (value > 767)
{
int temp = 2 * (896 - value);
uint8_t& r = ledValues[6 * 3 + 0];
uint8_t& g = ledValues[6 * 3 + 1];
uint8_t& b = ledValues[6 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[7 * 3 + 0];
uint8_t& g1 = ledValues[7 * 3 + 1];
uint8_t& b1 = ledValues[7 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
} else if (value > 639)
{
int temp = 2 * (768 - value);
uint8_t& r = ledValues[5 * 3 + 0];
uint8_t& g = ledValues[5 * 3 + 1];
uint8_t& b = ledValues[5 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[6 * 3 + 0];
uint8_t& g1 = ledValues[6 * 3 + 1];
uint8_t& b1 = ledValues[6 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[7 * 3 + 0];
uint8_t& g2 = ledValues[7 * 3 + 1];
uint8_t& b2 = ledValues[7 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
} else if (value > 511)
{
int temp = 2 * (640 - value);
uint8_t& r = ledValues[4 * 3 + 0];
uint8_t& g = ledValues[4 * 3 + 1];
uint8_t& b = ledValues[4 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[5 * 3 + 0];
uint8_t& g1 = ledValues[5 * 3 + 1];
uint8_t& b1 = ledValues[5 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[6 * 3 + 0];
uint8_t& g2 = ledValues[6 * 3 + 1];
uint8_t& b2 = ledValues[6 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[7 * 3 + 0];
uint8_t& g3 = ledValues[7 * 3 + 1];
uint8_t& b3 = ledValues[7 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
} else if (value > 383)
{
int temp = 2 * (512 - value);
uint8_t& r = ledValues[3 * 3 + 0];
uint8_t& g = ledValues[3 * 3 + 1];
uint8_t& b = ledValues[3 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[4 * 3 + 0];
uint8_t& g1 = ledValues[4 * 3 + 1];
uint8_t& b1 = ledValues[4 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[5 * 3 + 0];
uint8_t& g2 = ledValues[5 * 3 + 1];
uint8_t& b2 = ledValues[5 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[6 * 3 + 0];
uint8_t& g3 = ledValues[6 * 3 + 1];
uint8_t& b3 = ledValues[6 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
uint8_t& r4 = ledValues[7 * 3 + 0];
uint8_t& g4 = ledValues[7 * 3 + 1];
uint8_t& b4 = ledValues[7 * 3 + 2];
r4 = 0;
g4 = 0;
b4 = 0;
} else if (value > 255)
{
int temp = 2 * (384 - value);
uint8_t& r = ledValues[2 * 3 + 0];
uint8_t& g = ledValues[2 * 3 + 1];
uint8_t& b = ledValues[2 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[3 * 3 + 0];
uint8_t& g1 = ledValues[3 * 3 + 1];
uint8_t& b1 = ledValues[3 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[4 * 3 + 0];
uint8_t& g2 = ledValues[4 * 3 + 1];
uint8_t& b2 = ledValues[4 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[5 * 3 + 0];
uint8_t& g3 = ledValues[5 * 3 + 1];
uint8_t& b3 = ledValues[5 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
uint8_t& r4 = ledValues[6 * 3 + 0];
uint8_t& g4 = ledValues[6 * 3 + 1];
uint8_t& b4 = ledValues[6 * 3 + 2];
r4 = 0;
g4 = 0;
b4 = 0;
uint8_t& r5 = ledValues[7 * 3 + 0];
uint8_t& g5 = ledValues[7 * 3 + 1];
uint8_t& b5 = ledValues[7 * 3 + 2];
r5 = 0;
g5 = 0;
b5 = 0;
} else if (value > 127)
{
int temp = 2 * (256 - value);
uint8_t& r = ledValues[1 * 3 + 0];
uint8_t& g = ledValues[1 * 3 + 1];
uint8_t& b = ledValues[1 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[2 * 3 + 0];
uint8_t& g1 = ledValues[2 * 3 + 1];
uint8_t& b1 = ledValues[2 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[3 * 3 + 0];
uint8_t& g2 = ledValues[3 * 3 + 1];
uint8_t& b2 = ledValues[3 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[4 * 3 + 0];
uint8_t& g3 = ledValues[4 * 3 + 1];
uint8_t& b3 = ledValues[4 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
uint8_t& r4 = ledValues[5 * 3 + 0];
uint8_t& g4 = ledValues[5 * 3 + 1];
uint8_t& b4 = ledValues[5 * 3 + 2];
r4 = 0;
g4 = 0;
b4 = 0;
uint8_t& r5 = ledValues[6 * 3 + 0];
uint8_t& g5 = ledValues[6 * 3 + 1];
uint8_t& b5 = ledValues[6 * 3 + 2];
r5 = 0;
g5 = 0;
b5 = 0;
uint8_t& r6 = ledValues[7 * 3 + 0];
uint8_t& g6 = ledValues[7 * 3 + 1];
uint8_t& b6 = ledValues[7 * 3 + 2];
r6 = 0;
g6 = 0;
b6 = 0;
} else if (value < 128)
{
int temp = 2 * (256 - value);
uint8_t& r = ledValues[1 * 3 + 0];
uint8_t& g = ledValues[1 * 3 + 1];
uint8_t& b = ledValues[1 * 3 + 2];
if (r > temp)
{
r = r - temp;
} else {
r = 0;
}
if (g > temp)
{
g = g - temp;
} else {
g = 0;
}
if (b > temp)
{
b = b - temp;
} else {
b = 0;
}
uint8_t& r1 = ledValues[2 * 3 + 0];
uint8_t& g1 = ledValues[2 * 3 + 1];
uint8_t& b1 = ledValues[2 * 3 + 2];
r1 = 0;
g1 = 0;
b1 = 0;
uint8_t& r2 = ledValues[3 * 3 + 0];
uint8_t& g2 = ledValues[3 * 3 + 1];
uint8_t& b2 = ledValues[3 * 3 + 2];
r2 = 0;
g2 = 0;
b2 = 0;
uint8_t& r3 = ledValues[4 * 3 + 0];
uint8_t& g3 = ledValues[4 * 3 + 1];
uint8_t& b3 = ledValues[4 * 3 + 2];
r3 = 0;
g3 = 0;
b3 = 0;
uint8_t& r4 = ledValues[5 * 3 + 0];
uint8_t& g4 = ledValues[5 * 3 + 1];
uint8_t& b4 = ledValues[5 * 3 + 2];
r4 = 0;
g4 = 0;
b4 = 0;
uint8_t& r5 = ledValues[6 * 3 + 0];
uint8_t& g5 = ledValues[6 * 3 + 1];
uint8_t& b5 = ledValues[6 * 3 + 2];
r5 = 0;
g5 = 0;
b5 = 0;
uint8_t& r6 = ledValues[7 * 3 + 0];
uint8_t& g6 = ledValues[7 * 3 + 1];
uint8_t& b6 = ledValues[7 * 3 + 2];
r6 = 0;
g6 = 0;
b6 = 0;
}
}