Intellivision has 16 digital direction and no one else has made them. All digital joystick has always been made with 8 directions (4 buttons + diagonals)
If I were making analog stick for 8 directions, it would have been easy because it'd be square grid for determining what direction the stick is, such as top 1/3 for up, bottom 1/3 for down, left 1/3 for left and 1/3 right, and pass that as direction data.
But 16 is different. I didn't do well on complex math so I have no idea how to read X and Y value and convert them to 16 directions or neutral. The picture above sorts of illustrates the layout on X and Y value (the neutral range doesn't need to be large as pictured but needs to be just large enough that it won't trigger direction just by sneezing). I think this requires understanding in polar math? Something higher than algebra for sure.
Or is there a 16 direction digital joystick that doesn't cost much?
Triganometry is what you need as with this you can work out how long the hypotenuse is (less than x and it's neutral zone) and it's angle (360/16 is direction)
guess I'll have to find someone that is good in that and have him come up with computations that I can feed into Arduino. Most Arduino's analog has resolution of 1024 (10 bits ADC) so 512 steps from center to edge. If I can get the numbers I should be able to figure how to make it work in Arduino.
Angle is 22.5 degree for each of the 16 sections. So code example would be something like
if hypotenuse is <= 150, do nothing (stick is inside neutral area)
if hypotenuse is > 150 (outside neutral area) and angle is => 349.75 and angle is < 11.25 then do north
if hypotenuse is > 150 (outside neutral area) and angle is =>11.25 and angle is < 33.75 then do north+north+east,
etc... (have equal and greater then or equal and less than to avoid skipping when it is at exact 22.5' in between section)
Should have taken up more advanced math back in high school when I had the chance. Algebra was minimum for graduation and I didn't take up any more math classes after that.
Better stop thinking, my room is starting to smell like burning electricity
Actually I think geometry would work. X and Y would be known variable from the controller and can be used to make the 2 sides of a triangle with 90 degree corner. That would leave figuring the hypno and angle, and those stuff are in geometry which is a bit above algebra.
Subtract 512 from both x and y to get the center origin, then compute the hypno to determine if it was outside neutral range, and angle to figure what direction it was in.
wilykat:
But 16 is different. I didn't do well on complex math so I have no idea how to read X and Y value and convert them to 16 directions or neutral.
Fairly straightforward:
float angle = atan2 (y, x) ; // convert cartesian to polar angle
int segment = round (angle * 8 / PI) ; // 16 segments over 2 pi radians, round to integer...
segment &= 15 ; // modulo 16 (avoid negative values)
boolean neutral = x*x + y*y < threshold ; // is magnitude of vector small?
wilykat:
Actually I think geometry would work. X and Y would be known variable from the controller and can be used to make the 2 sides of a triangle with 90 degree corner. That would leave figuring the hypno and angle, and those stuff are in geometry which is a bit above algebra.
Subtract 512 from both x and y to get the center origin, then compute the hypno to determine if it was outside neutral range, and angle to figure what direction it was in.
Am I on the right track?
You call it geometry I call it trigonometry, maybe it's a culture/locale/age thing but yes you are on the right track.