2013-07-05 2 views
0

나는 다음과 같은 코드를 가지고있다. http://pastebin.com/25ugwNhK# 기본적으로 7 개의 다른 주파수에 대한 이퀄라이저 색 값을 읽고 그것들을 색으로 매핑한다. 그런 다음 양쪽 끝에서 시작하는 문자열에 투영됩니다.WS2801 LED로 어레이를 미러링하는 방법은 무엇입니까?

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]의 배열로 작업 할 수 있도록하고 싶습니다. 나는 FastSPI_LED 라이브러리를 사용하여 WS2801 조명 내 아두 이노를 통해이 프로그램을 실행할 때 나는 단지 빛을 하나 개의 행을 얻을, 그러나

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++; 
} 
} 
} 

그것은 순환을하지 않습니다

내 의사 코드는 다음과 같이 보입니다 모든 행?

답변

0

rows for() 루프를 반복 할 때마다 cols을 0으로 재설정해야합니다. 당신은 전체 화면 그리드를 완료 한 후에 만 ​​또는 모든 행 readEQ를 호출해야하는 경우

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 

덧붙여, 그것은 분명하지 않다 - 각 (업데이트의 자기 일관성 대 부분 반응의 속도) 다양한 장점이있을 것이다

관련 문제