lately i have been playing around with my wii nunchuk again using the joystick axes to control an el cheapo stepper motor using the received value to control the pause between steps for control of its rotational speed from slow to fast or vice versa.
the neutral value for the axis rests at 128 and i have had no problem scaling the pause value for it from the joystick input of 0 to 126 having a pause of 400 between steps if the axis value is 126 up to a pause 1 between steps if the stick is hard left with a 0 value.
the issue for me which i seem to get stumped on is scaling fro the opposite direction going from 130 to 255 and getting the pause going the same as the opposite direction in the manner of pause 400 for stick value of 130 to pause 1 for stick at 255.
i had used some scaling code that was shown to me to use for a different project in the past and was able to use the calculations to get the lower scaled pause value but have not been able to use it successfully to get the upper stick values scaled accordingly and now im a little stumped with it lol.
thanks,
tony
the neutral value for the axis rests at 128 and i have had no problem scaling the pause value for it from the joystick input of 0 to 126 having a pause of 400 between steps if the axis value is 126 up to a pause 1 between steps if the stick is hard left with a 0 value.
the issue for me which i seem to get stumped on is scaling fro the opposite direction going from 130 to 255 and getting the pause going the same as the opposite direction in the manner of pause 400 for stick value of 130 to pause 1 for stick at 255.
Code:
#com 3
#picaxe 20m2
symbol joy_x = b1
symbol joy_y = b2
dirsb=%00011110
Init:
i2cslave $A4, i2cslow, i2cbyte
Writei2c 0xf0,(0x55)
Pause 10
Writei2c 0xfb,(0x00)
Pause 10
retrieve:
writei2c (0)
Pause 10
Readi2c (joy_x,joy_y)
if joy_x <126 then pan_left
if joy_x> 130 then pan_right
goto retrieve
pan_left:
for b10=0 to 3
lookup b10,(%00011000,%00001100,%00000110,%00010010),pinsb
w2= joy_x*80/21+1
pause w2
next b10
goto retrieve
pan_right:
for b10=0 to 3
lookup b10,(%00010010,%00000110,%00001100,%00011000),pinsb
w3= ??????
pause w3
next b10
goto retrieve
i had used some scaling code that was shown to me to use for a different project in the past and was able to use the calculations to get the lower scaled pause value but have not been able to use it successfully to get the upper stick values scaled accordingly and now im a little stumped with it lol.
thanks,
tony