2013-12-11 54 views
1

我試圖做一個顏色數組,但不幸的是廷克庫似乎不支持數組:Arduino:列表?或同等

Tinker::Vect3d<float> rndCol[5]; 

rndCol[0] = {255,0,0}; 
rndCol[1] = {0,255,0}; 
rndCol[2] = {0,0,255}; 
rndCol[3] = {255,165,0}; 
rndCol[4] = {5,125,200}; 

soundLvel:47: error: expected constructor, destructor, or type conversion before '=' token 
soundLvel:48: error: expected constructor, destructor, or type conversion before '=' token 
soundLvel:49: error: expected constructor, destructor, or type conversion before '=' token 
soundLvel:50: error: expected constructor, destructor, or type conversion before '=' token 
soundLvel:51: error: expected constructor, destructor, or type conversion before '=' token 

因此,Arduino的支持列表或相當於我可以存儲這些英寸我無法找到任何參考。

回答

1

您可以只創建一個二維數組來存儲你的RGB顏色值:

int colourArray[5][3] = 
{ 
    {255,0,0}, 
    {0,255,0}, 
    {0,0,255}, 
    {255,165,0}, 
    {5,125,200} 
}; 

注意,在[5][3] 5是可選的,如果忽略([][3]),它會自動分配給元素的數量,您初始化。

雖然每次只能訪問一個元素,但如果要將它們分配給其他數組,則需要遍歷3個RGB子元素。例如:

int some_colour[3]; 
for(int i=0; i<3; i++) 
{ 
    some_colour[i] = colourArray[2][i]; 
}