0

我有以下代码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 库通过带有 WS2801 灯的 arduino 运行此程序时,我只能点亮一行并且它不会循环遍历所有行?

4

1 回答 1

0

您需要在for() 循环cols的每次迭代开始时重置为 0 。rows

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,或者仅在完成整个显示网格后调用 - 每个都有各种优势(部分响应率,与更新的自一致性)

于 2013-07-05T21:19:08.603 回答