servo controlling with switches
science_geek
Posts: 247
im working on interfacing an atari controller or a pair of dpdt switches that will control the servos, if you could please tell me how or send me a sample code i could modify it would be much appreciated
Comments
Regards
Duncan
Get some code to read the switches... up, down, left, right.
Have your code center the servos at start up.
Have 2 variables one for each axis. lets say X and Y
the X and Y variables would need to be initialized to center the servos
Then enter a loop that watches for the joystick directions (buttons)
if Left is detected then subtract 200 from X, if right is detected then add 200.
so by repeating the loop it will continue to increase\lower the freq. thus moving the servo.
Have the same thing for the Y axis.
The numbers above would need to be adjusted depending on the servo you have and other aspects. you would also want to add in a pause in the main loop so you have some control over the speed of the servo movement.
If the joystick does have pots in it then you would need to use the RCtime command to read the value of the joystick in each axis and then come up with a formula that would change the resistance values to proportionally match the freq that you servo needs.
good luck.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman
Post Edited (Dgswaner) : 5/18/2007 4:19:18 AM GMT
Not knowing the model number I don't know the answer, but if you have it sitting in front of you Google should be able to help...
HTH
Regards
Duncan
here is some sample code :
This is code from the Roaming with Ping. This is the part of the code to move the BoeBot (servos) Forward. you can find the entire code here
www.parallax.com/detail.asp?product_id=28015 look near the bottom
Forward_Pulse: ' Send A Single Forward Pulse
PULSOUT PingServo, 2000 ' Ping Servo Forward Pulse Value
PULSOUT LeftServo, 850 ' Left Servo Forward Pulse Value
PULSOUT RightServo, 650 ' Right Servo Forward Pulse Value
PAUSE 20 ' Refresh Delay
RETURN
attached is some code I used to test an IRPD sensor. the concept is the same as what you would need to detect the joystick. take a look at the code and if you still need help I'll see if I can't whip up some demo code tonight.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The 7800 uses a serial protocol, so SERIN would be the command to use in your Pbasic program. See the page above for serial specs and wiring suggestions.
Once you've got your Stamp successfully reading and/or storing the "read" values from the joystick, then it will be time to attack the code to make it all do something useful. One thing I would consider if you have the hard-wired 2600 joysticks -- see if the output from the joystick is already "debounced" -- if not, you'll need to account for that in your code. See the BUTTON command in the Pbasic Manual for info about debounce and methods for dealing with it.
P.S. -- I checked out the page again in more detail -- the 2600 joystick uses 5v at 50ma, so you would only need to limit current on the Stamp input pin(s) -- so you don't short things out if you make that pin an output or if the Stamp would otherwise be forced to sink or source too much current from the joystick. A 220ohm resistor would probably be fine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
This doc is for the Propeller, but it shows the NES controller setup, pinout, SPI protocol, etc. so it should be easy enough to hookup to a Stamp and use SHIFTIN to clock and read data.
If you have more questions in general about the NES controller, you might want to try over in the Hydra forum as that board uses NES connectors and the Hyrdra folks seem to be pretty up on these joysticks.
www.parallax.com/dl/docs/prod/prop/Hydra-Ch6All-v1.0.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST