Discussion forum for the BasicX family of microcontroller chips.
|
Hey all, I'm trying to run two servo motors with two pots. I am not sure of how to code it so each set would run seperately. this is my code and it doesn't work. what am i doing wrong? thnx dim minPulse as single ' the minimum pulseWidth dim maxPulse as single ' the maximum pulseWidth dim pulseWidth as single ' the servo's pulsewidth dim pulseRange as single ' the range of possible pulses dim sensorValue as integer ' for the pot Sub main() call delay(0.5) ' start program with a half-second delay minPulse = 0.0015 maxPulse = 0.0022 pulseWidth = minPulse pulseRange = maxPulse - minPulse ' the main loop: do sensorValue = getADC(13) sensorValue2 = getADC(15) debug.print "getADC(15)="; Cstr(getADC(15)) call pulseOut(12, pulseWidth, 1) if (getpin(15)<50) then call secondServo() end if pulseWidth = minPulse + ((pulseRange * cSng(sensorValue)) / 1023.0) loop End Sub sub secondServo() call pulseOut(8, pulseWidth, 1) end sub |
|
|
|
thank you all, it is solved. lg --- In , "limorgarcia" <limorgarcia@y...> wrote: > Hey all, > I'm trying to run two servo motors with two pots. I am not sure of > how to code it so each set would run seperately. this is my code and > it doesn't work. what am i doing wrong? > thnx > > dim minPulse as single ' the minimum pulseWidth > dim maxPulse as single ' the maximum pulseWidth > dim pulseWidth as single ' the servo's pulsewidth > dim pulseRange as single ' the range of possible pulses > dim sensorValue as integer ' for the pot > Sub main() > call delay(0.5) ' start program with a half-second delay > minPulse = 0.0015 > maxPulse = 0.0022 > pulseWidth = minPulse > > pulseRange = maxPulse - minPulse > > ' the main loop: > do > sensorValue = getADC(13) > sensorValue2 = getADC(15) > debug.print "getADC(15)="; Cstr(getADC(15)) > > call pulseOut(12, pulseWidth, 1) > if (getpin(15)<50) then > call secondServo() > end if > > pulseWidth = minPulse + ((pulseRange * cSng(sensorValue)) / 1023.0) > loop > > End Sub > > sub secondServo() > call pulseOut(8, pulseWidth, 1) > > end sub |