Shop OBEX P1 Docs P2 Docs Learn Events
Control of a servo with a mouse — Parallax Forums

Control of a servo with a mouse

BoneyardBoneyard Posts: 10
edited 2004-07-29 02:01 in BASIC Stamp
Im new to the Basic stamp. But learning.
I would like to control 2 servos with a optomechanical mouse or a new style optical.
Im trying this project with a logitech track ball to start off (its what I had handy)
So far im able to control one servo in one direction·by moving the track ball in any direction. The servo responds, but when I stop the ball movement the servo does not hold position, My other problem is having the two servos understand the x,y axis of the track ball.
so when·I move the track ball along the x axis one servo moves back and forth and when·I move the trackball along the y axis the other servo moves.
here is the code I have come up with. I do not know If it is even close.
Help Please.


'P0 to cs

'P1 to Data

'P2 to Clock

'P7 to servo





cs var out0

clock var in1

Do var in2

Servo var out15

moused var bit

mousein var byte 'mouse clock line

pass var bit

servotime var word



programtop:

dirL=%1011

dirH=11111

mousein=1

cs=1

clock=1

debug "starting"

'*****************************************

looptop:

clock=0

pass=0

mousein=1

cs=0

getmousein

moused=moused << 1

pulsout 1,2

moused=do

moused=moused

pass=pass+2

if pass >9 then getmousein

cs=1

'*****************************************

pulsout 15,1500

pulsout 15,0





servotime = moused * 5

pulsout 15,servotime

pulsout 6,500









goto looptop

goto programtop

Comments

  • BoneyardBoneyard Posts: 10
    edited 2004-07-29 02:01
    hers my updated code

    '{$STAMP BS2}



    'P0 to cs

    'P1 to Data

    'P2 to Clock

    'P7 to servo





    cs var out0 'chip select line

    clock var out1 'chip clock line

    Do var in2 'Chip data input line

    Servo con 15 'servo output data

    moused var bit 'mouse input value

    mousein var byte 'mouse clock line

    pass var bit 'loop counter variable

    servotime var word 'output time for servo













    programtop:

    dirL=%1011 ' set low byte of IO direction

    dirH=11111

    mousein=1

    cs=1 'set chip select nominal state

    clock=1 'set clock nominal state to reset chip

    debug "starting"

    '*****************************************

    looptop:

    ' start a loop that reads the data from the mouse

    clock=0

    pass=0

    mousein=1

    cs=0

    ' clock the data in



    getmousein:

    moused=moused <<1 'shift the data bits in the value variable

    pulsout 1,2 'strobe the clock bit

    moused=do 'get the data and stuff it into a bit var

    moused=moused 'or the bit var with the value variable

    pass=pass+2 'increment the bit counter

    if pass >9 then getmousein 'if not 8 bits done do again

    cs=1 'end read with chip select

    ' the data is now read into the

    ' mouse variable and can be used for

    ' other things



    '*****************************************

    ' start a servo output time calculation

    ' based on the read data

    servotime = moused * 5

    pulsout 15, 1500-0 'send the pulse to the servo on pin 15

    pulsout 15,servotime

    pulsout 6,500 'send a dummy pulse on pin 6 (unused)

    ' to slow the loop down for the servo



    goto looptop

    goto programtop





















Sign In or Register to comment.