Joystick PWM?

I'm trying to control several high-current motors with an H-bridge circuit, and I need to be able to drive the DC motors at variable speed (hence the PWM) with the arduino, with a joystick. What I'm attempting to do is to control these motors with the joysticks of a PS1 controller, but I've had some trouble finding information on how to script PWM control to a joystick on the playground. Any ideas?

If the PS1 controller is analog, the "Knob" example in the Servo library should already be pretty close to what you want.

But, at the very least, it should give you some hints on how to turn the joystick readings into PWM outputs.

Ran

how to script PWM control

Have a look at the sketch examples that use "analogWrite()", and the documentation for that function.

Indeed, the knob and analogWrite() sketches seem to be rather perfect for my purposes, but a new question arises: how do I get the joystick signals from the Logitech controller that I'm using in place of a conventional PSX controller?
(http://www.logitech.com/index.cfm/gaming/pc_gaming/gamepads/devices/288&cl=US,EN)
I could find a PSX controller somewhere, but is there any way to get the joystick positions from the serial port of the Arduino? The only source I've found on the playground implies that the controller is plugged into several of the pins on the arduino; this might be more difficult given the nature of the Logitech joystick (usb). Any thoughts?

The Arduino can't read that USB gamepad directly, because it can only be a USB "slave", not a "master".

With that controller, you're pretty much limited to either using a PC or other device that can act as the master (the correct term is "host", but it's not as clear) and pass the readings along as, say, a serial port message, or cutting the gamepad open and wiring its joysticks to the Arduino's analog inputs.

Personally, if I didn't already have an old analog joystick hanging around, I'd check the thrift stores and flea markets for one. Sparkfun sells the little "thumb-sized" joysticks as a component, if you want to build your own control box.

Ran

How exactly does one get a serial input from a computer and use it to control the digital pins on the arduino? I'm a little confused about what computer program/arduino code might be used in order to get the joystick/controller inputs to the arduino.

If you send serial data from the host computer, the Arduino sketch can use 'Serial.read()' to read it. There's also 'Serial.available()' so that you can tell when there is serial data waiting to be read in.

I've got the serial end of the problem pretty solid now; the next issue seems to be getting the joystick data into the PWM modulation for the motors. As they are attached to a motor shield with a high/low logic table, I'm not 100% certain how to convert the magnitude reading of the joystick into the timing data needed for the PWM. In other words, does the analog(write) function output in terms of power or timing?
Also, what might the maximum and minimum PWM values be? (Like how the servo range is 0-255)

You can call 'analogWrite()' with a value 0-255 that represents the average voltage of the output. So if you use 0, you get 0V, 128 gives (average) 2.5V, 255 gives 5V.