Yes, you should set it to a number. Here’s why:
The logical test in the code first says “Hey, the joystick is being pressed… light up this LED” then it says “Hey, this button is pressed, light up this LED and the one next to it”. You can see this in kaimana.cpp:
if(index == LED_JOY)
{
index = 8;
_led[index].r = iR*BRIGHTNESS;
_led[index].g = iG*BRIGHTNESS;
_led[index].b = iB*BRIGHTNESS;
}
else
{
_led[index].r = iR*BRIGHTNESS;
_led[index].g = iG*BRIGHTNESS;
_led[index].b = iB*BRIGHTNESS;
_led[index+ 1].r = iR*BRIGHTNESS;
_led[index+ 1].g = iG*BRIGHTNESS;
_led[index+ 1].b = iB*BRIGHTNESS;
}
NOTE: This is the PFS2.0 specific code from the BrightStick site where the JOY is the 9th LED in the series ( but really indexed value of 8 because in programming arrays starts with 0). So for non Panzer installs (or installs that dont follow my PFS2 LED scheme) can remove the line:
index=8;
since you will set the LED index for LED_JOY properly. You could also just update that line to have the correct index number for your case, but that would be redundant. If you remove it though, the code will take the index value and use it properly lighting the LED up in the joystick.
Here’s what’s going on:
It has to do it this way (handle the JOY LED first in all cases, hence an IF->ELSE statemnt) because the LEDs are in series with two per button. If you just set the JOY to a number and follow the same logic it will light one of the LEDs on button A and then the next LED on button B for Kaimana Js installed after the JOYSTICK and nobody wants that.
In the case of the Panzer 2 setup, the first LED set in the string is for K4. So you have the single button:
With the pair of LEDs under it:
(LED 0 --> LED 1)
The code I mention above says: set LED at position 0 to “R” “G” “B” values (with some brightness modification) and then set the LED one position down the line (in this case LED 1, which is the other half of the K4 button lighting and evident by [index+1] ) to the same value WHEN K1 is pressed.
Now… let’s think forward to K1 the JOYSTICK and P1. The LEDs are setup such that:
|— KICK 1—| | JOY | |—PUNCH 1—|
LED 6 --> LED 7 --> LED 8 --> LED 9 --> LED 10
With the code above, it does it right. You press one of the directions on the Joystick, the code senses those digital pins and says “Hey! Light up the LED Joy at this index and only at this one index”… so it passes the index number (via some complex code in the .ino file) to the block of code. Since the index is the JOY index it enters that first “if” statement and then lights up the correct LED completely bypassing the else statement like it didn’t exist.
Say, for example, we didn’t have that first “if” statement in there and the code within the “else” brackets was the only bit in this function…
It would pass the index for the JOY, 8 in our case, and light up LED 8 AND LED 9. So the JOY LED would light and then the bottom half of PUNCH 1’s Kaimana J would light up. WHOOPS!
Hopefully this demystifys some of the magic happening here.