Guten Morgen,
Ich habe hier eine Routine gefunden, die im Zusammenhang mit einer
anderen, einen "Nightrider" Effekt nachbilden soll.
Das Funktioniert auch komischer weise?!
1 | void Set_Channel_Pwm(uint8_t LedNum, uint8_t Rotation)
|
2 | {
|
3 | uint8_t d = 0;
|
4 |
|
5 | for (uint8_t Index = 0; Index < 4; Index++)
|
6 | {
|
7 | /* calculate next index */
|
8 | if (Rotation) // Rotation = 1 ?
|
9 | d = (uint8_t)((Index) - (LedNum));
|
10 | else // Rotation = 0 ?
|
11 | d = (uint8_t)((LedNum) - (Index));
|
12 |
|
13 | if (d == 0)
|
14 | pwm.Ch[Index] = 75; // led 3
|
15 | else if (d == 1)
|
16 | pwm.Ch[Index] = 25; // led 4
|
17 | else if (d == 2)
|
18 | pwm.Ch[Index] = 10; // led 5
|
19 | else if (d == 3)
|
20 | pwm.Ch[Index] = 5; // led 5
|
21 | else
|
22 | pwm.Ch[Index] = 0; // all other led´s
|
23 | }
|
24 | }
|
Wenn ich jetzt davon ausgehe, dass meine Variable Index = 0 ist und
LedNum einen Wert von 3, da müsste die Variable doch überlaufen und das
ganze nicht mehr wirklich funktionieren, weil Werte 252 und Co.
Nur wieso klappt alles?
Mfg der Peter K.