我有以下代码http://pastebin.com/25ugwNhK#,它基本上读取7个不同频率的均衡器颜色值并将它们映射到一种颜色。然后镜像它们从两端开始投射到一个字符串上。
void EQcenterBarString(){
// reads eq and plugs RGB values directly into each consecutive pixel, mirrored from center.
if(LoopCnt <= PixelCount) {
readEQ();
//Add new color to array at pointer position
//For Array replace LoopCnt with row number
leds[LoopCnt].r = ledRed;
leds[LoopCnt].g = ledGreen;
leds[LoopCnt].b = ledBlue;
//now the opposite
//For Array replace Pixel - Loop with ROWS - row number
leds[PixelCount - LoopCnt].r = ledRed;
leds[PixelCount - LoopCnt].g = ledGreen;
leds[PixelCount - LoopCnt].b = ledBlue;
FastSPI_LED.show();
LoopCnt++;
}else{LoopCnt=0;}
}
我想让它能够使用[ROWS] [COLS]的数组,但是我很惊讶让像素更新或循环遍历数组。
我的伪代码看起来像这样:
void EQcenterBarArray(){
int pixel = 0, rows = 0, cols = 0;
//rows = 0, loop through till the end going down the array, rows++
for(rows = 0; rows < ROWS; rows++) {
readEQ();
// should light up a whole row at once starting from the beginning of the array
while (cols != COLS) { //while in row # x fill all the col values until = COL value
pixel = ( LEDmatrix[rows][cols] ); // set pixel index to the array pos
leds[pixel].r = ledRed;
leds[pixel].g = ledGreen;
leds[pixel].b = ledBlue;
FastSPI_LED.show(); //update the pixel and move to next col value
cols++; //should fill whole col on row x ?
}
//now the opposite side
// should light up a whole row at once starting from the end of the array
while (cols != COLS) {
pixel = ( LEDmatrix[(ROWS-1) - rows][cols] ); //take the total# of ROWS and subtract the current row value to create a mirror effect?
leds[pixel].r = ledRed;
leds[pixel].g = ledGreen;
leds[pixel].b = ledBlue;
FastSPI_LED.show();
cols++;
}
}
}
然而,当我使用FastSPI_LED库通过我的arduino运行WS2801灯时,我只会点亮一行并且它不会遍历所有行?
答案 0 :(得分:0)
您需要在cols
for()循环的每次迭代开始时将rows
重置为0.
for(rows = 0; rows < ROWS; rows++) {
readEQ();
// should light up a whole row at once starting from the beginning of the array
cols = 0; //reset cols to zero to iterate next set of columns
while (cols != COLS) { //while in row # x fill all the col values until = COL value
顺便说一句,不清楚你是应该每行调用readEQ,还是只在你完成一个完整的显示网格之后 - 每个都会有各种优势(部分响应率和更新的自我一致性)< / p>