【发布时间】:2021-01-12 11:20:17
【问题描述】:
我正在使用 Arduino ESP8266-1 和 RGB LED 灯条做一个项目。 ESP 通过串行向 Arduino 发送带有要设置的颜色名称的字符串(例如:“red”、“yellow”、“purple”),我需要将该字符串转换为 RGB 值(例如(255, 100, 255))。
我该怎么做?
我尝试创建一个具有如下值的数组列表:
int red = {255, 0, 0};
循环中的下一个:
String com = "red";
if (com == "red") {
colorLed = red;
}
但如果有更多颜色,这不是最好的方法。有什么更好的方法?
【问题讨论】:
-
发送颜色名称而不是 rgb touple 有什么好的理由吗?
-
因为 esp 已连接到谷歌助手,谷歌在我的命令中向我发送字符串,如:"{"deviceId":"xxx","action":"action.devices.commands.ColorAbsolute", "值":{"颜色":蓝色}}"
标签: arduino rgb lookup-tables arduino-c++