Switch with Servo

I was wondering i there was anyway to program a servo to be activated on a rocker switch instead of with a petentiometer, such as have it rotate 180 degrees or something?

servo = 127
if sw1 = 1 then servo = 254
if sw2 = 1 then servo = 0

you’re positive this would work? i’ve been argueing with our programmer that it is possible.

*Originally posted by rust710 *
**servo = 127
if sw1 = 1 then servo = 254
if sw2 = 1 then servo = 0 **

*Originally posted by pras870 *
**you’re positive this would work? i’ve been argueing with our programmer that it is possible. **

With this code, the servo will normally be in a centered position, and whenever the rocker switch is thrown, the servo will turn to the corresponding extreme. The servo will return to the centered position whenever the rocker switch is in its centered position.

If you would rather have the servo only go from one extreme to the other, you might want something more like this:


servo = 0

main_loop:
...
if sw1 = 1 then servo = 254
if sw2 = 1 then servo = 0

YEP…

We used just that to activate a “brake” pin in our gearboxes last year…works fine…

*Originally posted by EricS-Team180 *
**YEP…

We used just that to activate a “brake” pin in our gearboxes last year…works fine… **

Our team did the same thing two years ago, and we’re doing it this year too. It works great.

we’re using a rocker switch. Right now the code we have is this:

p1_wheel = 0
if p3_sw_aux2 = 0 then p1_wheel = 0
if p3_sw_aux2 = 1 then p1_wheel = 63

since the servo is on PWM 9 we’re using p1_wheel variable, but yusing the roboemu program, the wheel on the joystick moves the server but not aux2, any help would be appreciated.

*Originally posted by pras870 *
**we’re using a rocker switch. Right now the code we have is this:

p1_wheel = 0
if p3_sw_aux2 = 0 then p1_wheel = 0
if p3_sw_aux2 = 1 then p1_wheel = 63

since the servo is on PWM 9 we’re using p1_wheel variable, but yusing the roboemu program, the wheel on the joystick moves the server but not aux2, any help would be appreciated. **

If you email me your code, I’d be happy to take a look. RoboEmu doesn’t currently have any known issues that would affect code like the stuff you posted, so it’s probably a line somewhere farther down overriding your code. Anyways, let me know. [email protected]

I also found out today that any wheel on a joystick controls p1_wheel, it’s strange if you ask me.

*Originally posted by pras870 *
**I also found out today that any wheel on a joystick controls p1_wheel, it’s strange if you ask me. **

Pras,

There’s just not enough info to go on here. I suggest you do as Rob suggests, and send him your code. Better yet, post it here, and you can have a bunch more pair of eyes looking at it at the same time.