neiltechspec
Senior Member
My points controller does 5 servos activating sets of points on my N Guage Railway.
Inputs are switches and can be left in either position (on / off), when a switch changes I want to
move the appropriate servo & then turn the servo off after about 200ms (should give enough time for servo to move).
Current code is below, but can't seem to get my head around the best way to achieve what I need.
Any ideas welcome.
Inputs are switches and can be left in either position (on / off), when a switch changes I want to
move the appropriate servo & then turn the servo off after about 200ms (should give enough time for servo to move).
Current code is below, but can't seem to get my head around the best way to achieve what I need.
Any ideas welcome.
Code:
#rem
Servo based independant five points controller
for changing loop & siding servos.
V1 30th Dec 2019
Servo 1 & 2 for changing between loops
Servo 3 for siding 1
Servo 4 for siding 2
Servo 5 for siding 3
min position is 100
centre is 150
max position is 200
Servo 1 on B.1
Servo 2 on B.2
Servo 3 on B.3
Servo 4 on B.4
Servo 5 on B.5
Switch for servo 1&2 on C.0
Switch for servo 3 on C.1
Switch for servo 4 on C.2
Switch for servo 5 on C.3
Led on C.4
#endrem
#picaxe 14m2
#no_data
#terminal 19200
symbol s1 = B.1
symbol s2 = B.2
symbol s3 = B.3
symbol s4 = B.4
symbol s5 = B.5
init:
setfreq m16
low C.4 'led off
sertxd("Reset",cr,lf)
pullup 3840 'pullup on C.0 to C.3 (%0000111100000000)
servo s1,135 'start servo 1 in inactive position
servo s2,170 'start servo 2 in inactive position
servo s3,120 'start servo 3 in inactive position
servo s4,155 'start servo 4 in inactive position
servo s5,145 'start servo 5 in inactive position
pause 2000
sertxd("Servo's started in inactive postion",cr,lf)
pause 1000
high C.4 'led on
sertxd("Run",cr,lf,cr,lf)
main:
do
if pinC.0 = 0 then gosub s1_2l
if pinC.0 = 1 then gosub s1_2r
if pinC.1 = 0 then gosub s3l
if pinC.1 = 1 then gosub s3r
if pinC.2 = 0 then gosub s4l
if pinC.2 = 1 then gosub s4r
if pinC.3 = 0 then gosub s5l
if pinC.3 = 1 then gosub s5r
pause 400
loop
s1_2l:
servopos s1,135 'servo 1 clockwise
servopos s2,170 'servo 2 anti-clock
pause 800
'servopos s1,OFF
'servopos s2,OFF
return
s1_2r:
servopos s1,175 'servo 1 anti-clock
servopos s2,140 'servo 2 clockwise
pause 800
'servopos s1,OFF
'servopos s2,OFF
return
s3l:
servopos s3,120 'servo 3 clockwise
pause 800
'servopos s3,OFF
return
s3r:
servopos s3,148 'servo 3 anti-clock
pause 800
'servopos s3,OFF
return
s4l:
servopos s4,155 'servo 4 anti-clock
pause 800
'servopos s4,OFF
return
s4r:
servopos s4,121 'servo 4 clockwise
pause 800
'servopos s4,OFF
return
s5l:
servopos s5,145 'servo 5 anti-clock
pause 800
'servopos s5,OFF
return
s5r:
servopos s5,176 'servo 5 clockwise
pause 800
'servopos s5,OFF
return