Im all new to the forum here and just getting started on my second arduino project. My first one was a mix of the Reverse Geocache box and the Bankvault Hack posted on Hackaday. I created a sort of puzzle box for my family for christmas. As it was a bit last minute i didn't document anything.
But anyways to the point.
I had this idea to mod a PS3 controller to give the force feedback to one of those ab toner belts (I know dont ask )
So the controller gives a PWM signal to the FFB motors.
Here comes in problem number 1:
How to measure the different signals which determine the vibration level?
Then onto the toner thing, pulled it apart and its easy to make a hardware interface as the controller is connected with a 2.5mm jack. It operates at a constant voltage and current only the pulse frequency changes.
Theres problem 2: would I use analogWrite() together with setPWMfrequency() to get this to work?
The hardware part is not really a problem it's more that I'm quite new to the arduino programming.
I looked into that and opened up the control box of the belt.
It is a bit over engineered so im planning to ditch that whole thing.
It originally works on AC but I think it should work with PWM DC.
The Arduino comes into play as I would like to make certain thresholds, for example in shooting games it ofcourse vibrates when shooting but more intensely when getting shot.
So I was thinking of using a fairly simple If() statement to do that. I just need a way of measuring the incoming pulses from the controller.
My guess would be that this creates a 50% duty cycle and by changing the delay I can alter the frequency.
Although I have read that with the delay function most of the Arduino functions stop and should use the millis() function.
How could I implement that?
Well if it is run in a loop it is HIGH 50% of the time and LOW 50% of the time. At least I would think so 10ms on, 10ms off, 10ms on....
Which should give a 50Hz frequency: 1000(ms)/20(period)
Please correct me if im wrong
It is the easiest I could come up with as the original controller gives out AC at varying frequencies.
If you want to implement your own PWM mechanism, you can't use delay(), as you've observed. So, using the millis() function is the way to go.
To use it, though, you need to record when the pin is set high (or low), and see if it is time to change the state of the pin. If it is, change the state and record the time. If not, do nothing.