Shop OBEX P1 Docs P2 Docs Learn Events
Pushbutton to Control Direction of Continous Rotation Servos — Parallax Forums

Pushbutton to Control Direction of Continous Rotation Servos

Modest ClownModest Clown Posts: 2
edited 2008-02-27 06:15 in BASIC Stamp
Hi Guys,

I'm new to stamps, and I was wondering if someone could help me figure out how to·create a ·simple Pushbutton sensor to help me control the direction of my servo motor.·Im pretty sure that I·have·the circuit connected properly I just need help with the coding aspect. I'm unfamilar with the commands for the stamps. I'm currently using the BS2. Would a TOGGLE·command be best or a IF ElSE··statement?

Thanks·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-27 05:37
    I suggest you become familiar with the commands for the Stamps. There are some excellent tutorials you can download from Parallax's website. In particular, look under "Support" in the "Downloads" tab under "Stamps in Class Downloads". You'll find "What's a Microcontroller?" and "Robotics with the BoeBot". The former has all sorts of examples for using pushbuttons while the latter will show you how to control a servo motor.
  • Modest ClownModest Clown Posts: 2
    edited 2008-02-27 05:46
    I know how to get the motor going, as well as the push button. the only problem is combining the two task.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-27 06:15
    The motor requires a pulse width from 1ms (PULSOUT pin,500) to 2ms (PULSOUT pin,1000) with one width representing rotation in one direction and the other representing rotation in the other direction. Actually, anything in the PULSOUT below around 750 will cause rotation in one direction and above 750 in the other.

    You need a program which will detect a pushbutton (using the BUTTON statement probably) that produces a value of 0 or 1. Simply compute a pulse width value based on that like buttonValue*500 + 500 will give a value of 500 if buttonValue is 0 and 1000 if buttonValue is 1.

    The check for the state of the button could be in the same loop as the PULSOUT for the servo since both need to repeated periodically.
Sign In or Register to comment.