Open
Description
Describe your feature request
A way to set axis values base on a numeric index rather than a specific axis name to allow looping. This could come in the form of a new function:
// Current function
setXAxis(xAxisValue);
// New function
setAxis(axisIndex, axisValue);
Additional context
I am using the library to create game controllers, and it is fantastic! One challenge is that I have to duplicate the code for each axis. I would like to be able to write a loop to apply the same code to all of the axes. Here's what I'm thinking:
Current version, has to be repeated for every axis.
// This code is more complicated if there is any smoothing or other conditionals applied.
// Code for the first axis
newXAxisValue = analogRead(xAxisPin);
if(oldXAxisValue != newXAxisValue)
{
setXAxis(newXAxisValue);
oldXAxisValue = newXAxisValue;
}
// Code for the second axis
newYAxis = analogRead(yAxisPin);
if(oldYAxisValue != newYAxisValue)
{
setYAxis(newYAxisValue);
oldYAxisValue = newYAxisValue;
}
// Have to repeat the code above for any additional axes...
New function, would allow for looping over as many axes as you wanted. This would be especially
nice with more complex code, e.g. smoothing via a rolling average.
// Single loop that sets ALL axes
// Write the code only once for as many axes as are used
for(i = 0; i < numAxes; i++)
{
newAxisValue[i] = analogRead(axisPin[i]);
if(newAxisValue[i] != oldAxisValue[i])
{
setAxis(i, newAxisValue[i]); // THIS IS A NEW FUNCTION
oldAxisValue[i] = newAxisValue[i];
}
}
Thanks,
Eric