Shop OBEX P1 Docs P2 Docs Learn Events
Bicolor LED and Servo — Parallax Forums

Bicolor LED and Servo

chasingchasing Posts: 14
edited 2010-12-19 12:17 in BASIC Stamp
Is it possible to use a bicolor LED to show the direction a servo is moving on a BOE with a BS2? I've used regular red LEDs to show if a servo was moving in my BOE-Bot projects, but that didn't differentiate between clockwise and counter clockwise movement; only off and on. Would I have to write two separate subroutines (one for clockwise and one for counterclockwise) or can I just use 'IF THEN" statements? Any suggestions would be appreciated.

Comments

  • BritannicusBritannicus Posts: 98
    edited 2010-12-19 07:57
    I'm not an expert, but I would have thought you could do this simply enough by adding a High and Low statement after your pulsout statement - this would use up 2 aditional ports though - you're going to have to write a line for your pulsout to define which directoin you are going to turn anyway

    so something like this to wag from side to side ? connect the LED to 12 and 13
    Do
    pulsout 14, 350 ' moves your servo to the right
    pause 20

    high 13 ' shows on bicolour
    low 12
    pause 500

    pulsout 14, 1150 ' moves your servo to the left
    pause 20

    low 13 ' shows the other bicolour ' reverses circuit
    high12
    pause 500

    loop
  • ercoerco Posts: 20,256
    edited 2010-12-19 08:21
    Or integrate them with your pulsout loops:

    (connect the LED to 12 and 13)

    direction 1: FOR B0=1 TO 100' one direction, varies by servo
    pulsout 14, 500' min value
    high 12
    pause 20
    low 12
    next

    direction2: FOR B0=1 TO 100' other direction
    pulsout 14, 1000' max value
    high 13
    pause 20
    low 13
    next

    goto direction1' repeat
  • chasingchasing Posts: 14
    edited 2010-12-19 11:03
    Thank you very much. After I posted (and slept) I realized the code would look something like what you both posted.
  • ercoerco Posts: 20,256
    edited 2010-12-19 12:17
    Slow motion is even better:

    direction 1: FOR W0=500 TO 1000 step 50' one direction, varies by servo
    pulsout 14, W0' min value
    high 12
    pause 20
    low 12
    next

    direction2: FOR W0=1000 TO 500 step 50' other direction
    pulsout 14, W0' max value
    high 13
    pause 20
    low 13
    next

    goto direction1' repeat
Sign In or Register to comment.