調整循環的起始和結束條件,以及數組索引的計算方式。修改后的代碼:
```c
void WaterLampToCol3(unsigned long _uColor, unsigned char _uTime)
{
unsigned char i;
for (i = 0; i < nWs; i++)
{
WsDat[i] = _uColor;
WsDat[nWs - 1 - i] = _uColor;
WS_L_SetAll();
delay_ms(_uTime);
}
reset();
}
```
1. 循環從 `i = 0` 開始,而不是 `i = nWs/2`。
2. 將 `WsDat[nWs/2 - (i - nWs/2)]` 改為 `WsDat[i]` 和 `WsDat[nWs - 1 - i]`,這樣就會先設置數組的兩端,然后逐漸向中間設置。
|