I wrote a quick and dirty using the 3 switches on the BB2 and 3 servos… I used HServo. I set it up such that you can set MIN/MAX values differently for each servo. I did different things for different buttons. So you should be able to mix and match to do however you want.
Switch A : Moves 2 servos in the same direction. Always the same direction…
Switch B : moves 2 servos in opposite direction. If you release the button and press again, then the both go the opposite direction of the direction they were going the previous time you pressed the button.
Switch C: only moves the 3rd servo. It goes all the way up to max, reverses direction and goes all the way to min…
[code]servo0 var sword
servo1 var sword
servo2 var sword
buttona var bit
buttonb var bit
buttonc var bit
s1Mult var sword
s2Dir var bit
btnbPrev var bit
S0MIN con -12000
S0MAX con 12000
INCRVAL con 250
S1MIN con -12000
S1MAX con 12000
S2MIN con -12000
S2MAX con 12000
servo0 = 0
servo1 = 0
servo2 = 0
s2Dir = 0
s1Mult = -1
btnbPrev = 0
sound 9, [100\880, 100\988, 100\1046, 100\1175]
start:
btnbPrev = buttonb ; save previous state.
buttona = in12
buttonb = in13
buttonc = in14
if buttona = 0 then button_a_process
if buttonb = 0 then button_b_process
if buttonc = 0 then button_c_process
goto start
button_a_process:
servo0 = servo0 + INCRVAL
servo1 = servo1 + INCRVAL
; sound 9, [60\4000]
goto servo_pulse_generation:
button_b_process:
if btnbPrev then
s1Mult = -s1Mult
endif
servo0 = servo0 + (INCRVAL * s1Mult)
servo1 = servo1 - (INCRVAL * s1Mult)
; sound 9, [60\4500]
goto servo_pulse_generation:
button_c_process:
; sound 9, [60\5000]
if s2Dir then
Servo2 = Servo2 + INCRVAL
if servo2 >= S2MAX then
servo2 = S2MAX
S2Dir = 0
endif
else
Servo2 = Servo2 - INCRVAL
if servo2 <= S2MIN then
servo2 = S2MIN
S2Dir = 1
endif
endif
servo_pulse_generation:
; make sure Servo 0 and 1 are in range…
servo0 = (servo0 max S0MAX) min S0MIN
servo1 = (servo1 max S1MAX) min S1MIN
HServo [p0\servo0, P1\servo1, P2\Servo2]
pause 25
goto start[/code]
I am not saying this is great code, but should get you moving.
Kurt