【发布时间】:2014-11-27 10:58:53
【问题描述】:
我正在做一些电子产品:我有 12 个 RGB LED 成一个圆圈(我称之为跟轮)。我将按照预定义的“级别”“脉冲”每种 LED 颜色:见下文,例如,LEVEL02 意味着 LED 的颜色将每 10 个周期脉冲两次……代码将循环通过所有 12 个 LED一次一个。 1 个周期 = 12 个 LED...10 个周期 = 一个色阶循环
基本上我想做的是说pixel[1] = colour1或pixel[5] = colour9等...其中pixel是我的数组heelwheel,colour是一组常量char数组@ 987654327@、clRRG 等...好的,更多详细信息:
// Color Level Definitions
#define LEVEL00 "0000000000"
#define LEVEL01 "1000000000"
#define LEVEL02 "1000010000"
等等...直到 LEVEL10
char heelwheel[12][3]; //wheel pixel: LED, Colour (Red, Green, Blue)
// Colour Definitions: defining mix of colour levels for 12 standard colours
//(12 coincidentally == the number of LEDs: no particular reason)
const char *clRED[3] = {LEVEL10, LEVEL00, LEVEL00} ; // full red
const char *clRRB[3] = {LEVEL06, LEVEL00, LEVEL04} ; // mostly red, bit of blue
const char *clRAB[3] = {LEVEL05, LEVEL00, LEVEL05} ; // purple
等... 12 种颜色
所以我想要做的是通过指定 12 种颜色中的 1 种来设置 12 个“像素”中的每一个...例如
heelwheel[0] = clRED ;
heelwheel[1] = clRRB ;
我希望很清楚我想要做什么......我的理论是我已经将heelwheel 定义为一个二维数组:我不想单独设置二维中的三个值,我只想说these three values = the three values contained in the three-value colour arrays
gcc error = "incompatible types when assigning to type char *[3] from type const char **"...
我试图了解 C 中有关数组的大量资源,但有些东西是“坚持”的,但我是 C 的初学者,所以我很快就进入了令人头疼的领域。
【问题讨论】:
-
而不是:heelwheel[0] = clRED;使用 memcpy( &heelwheel[0], clRED, sizeof(clRED) );
-
谢谢,我试试看!这可能会回答我的问题,而“放松”的答案在实用性/标准实践方面可能更有意义
标签: c gcc raspberry-pi