Shop OBEX P1 Docs P2 Docs Learn Events
servo — Parallax Forums

servo

corybcoryb Posts: 3
edited 2009-01-08 01:22 in BASIC Stamp
I'm trying to help my son with his microrobotics class.· He's got to make a servo move to indicate the temperature thats read by that sensor.· He's written the following code.· Do you guys think it'll work?· There's a whole bunch before this and after this that the teacher said didn't need to be changed.· I think it's the part that makes the temperature thingy work.· Thanks

' Main Program Code
'

Do
GOSUB SHT_Measure_Temp
pulses VAR Word
duration VAR Word
Main:
DEBUG DEC (tf/10)* 100, CR
DEBUG "tF.."
DEBUG "temp equal duration", CR
DEBUG DEC "duration"


DEBUG "servo is showing temp", CR
PULSOUT 14, duration
PAUSE 20
DEBUG "done"

· PAUSE 1000·························· ' minimum delay between readings
· Loop
· END

'
' Subroutines

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-01-08 01:22
    variable declaration should be at the beging of the program. Not sure if that's required or just tradition, but there you have it.

    The main label should be moved before the DO statement.

    You need to calculate duration somewhere. It looks like you have the equation in a debug statement, but you'll need to assign something to duration. Also, some boundary checks would be good to make sure that it doesn't over/under shoot and potentially damage the servo.

    Servos need to be refreshed every 20 ms or so. So, you have two options: just get rid of the PAUSE 1000 and shorten to the PAUSE 20 to about 15, or create a servo routine that lasts about 1000 ms. I like the latter.
Sign In or Register to comment.