Modifying Pulsout Duration. Spinning servos 5 times in 10 seconds
hp16
Posts: 11
I'm working on this thing right here. I think I understand it a little bit but I just have trouble with my code, I don't know how to modify it. I'll be posting it here, hopefully someone can explain to me if I'm doing it right or not. I have to write a program that will make the servos spin 5 times in 10 seconds with the push of a button. At the same time I have to set up two LEDs that will flash on and off every time the servo makes one complete revolution. This is what I've come up with so far.
DO IF(IN3=1) THEN FOR COUNTER = 1 TO ?? FOR COUNTER2 = 1 TO ?? PULSOUT 12, 777 PULSOUT 13, 726 PAUSE 20 NEXT HIGH 11 HIGH 10 PAUSE 125 LOW 11 LOW 10 PAUSE 125 NEXT ELSE ENDIF LOOP
Comments
I think you have the right idea with counters. You'll have to experiment with the speed numbers to get the servo to move at the desired speed. You should be able to come up with a reasonable guess of how many 20ms are in two seconds which will be your counter2 limiting value. The limit for "counter" should be obvious IMO (how many rotations do you want?).
So you have two continuous rotation servos and two LEDs right? How long are the LED flashes supposed to be?
I'd suggest running the servos off a regulated power source. If you run straight off the batteries the speed will change as the batteries lose their charge (this might not be big problem, a lot depends on what kind of batteries you use).
The one issue I see is the debug statement. I'm not sure how much that will throw off your timing.
An alternative to reducing the number of loops it to reduce the pause time. It's common to use pauses less than 20ms in order to compensate for code overhead.
I don't know if you plan to add something after "else" or not but if you're not, then you can probably just delete it.
If I reduce the pause from 20 ms to 10 ms thus requiring the for counter to be from 1 to 274, I'll need to declare a counter variable in Word instead of Byte. I think 20 ms is fine for now.
The Else is there so that after it completes the for counter next loop it's just gonna go through Do Loop forever, waiting to see if I press the button again.