' 08Srv_1D_151028 test servo
' modify to enable changing of servoMin,Max
#picaxe 08m2
symbol panSpot = b13
symbol tiltSpot = b12
symbol activeServo = b11
symbol activeSpot = b10
symbol lastSpot = b9
symbol servoMax = b8
symbol servoMin = b7
symbol pInPin = c.1
symbol panServo = c.4
symbol tiltServo = c.2
symbol cServoMin = 75
symbol cServoMax = 225
symbol cServoCenter = 150
symbol tiltMin = 140
symbol eepServoMin = 0 ' address of servoMin in eeprom
symbol eepServoMax = 1 ' address of servoMax in eeprom
eeprom eepServoMin,(cServoMin,cServoMax)
pause 2000 ' wait 2 seconds
read eepServoMin,servoMin,servoMax
sertxd("08Srv_1D_151028: min, max: ",#servoMin," ",#servoMax,cr,lf)
pause 8000 ' wait 8 seconds
activeSpot = cServoCenter
panSpot = activeSpot ' center
tiltSpot = activeSpot ' center
lastSpot = activeSpot - 1
'high 0 'set up for serout
ActiveServo = tiltServo ' tilt servo is active
gosub servoOut
ActiveServo = panServo ' pan servo is active
gosub servoOut
main:
do
' serin pInPin,N2400,b1
serin pInPin,T2400,b1
' serout 0,N2400,(b1, " ", #b1, " ")
select b1
case "p"
activeServo = panServo
activeSpot = panSpot
lastSpot = panSpot ' make sure we move with new servo
case "t"
activeServo = tiltServo
activeSpot = tiltSpot
lastSpot = tiltSpot ' make sure we move with new servo
case "m"
servoMin = servoMin - 5 min cServoMin
write eepServoMin,servoMin
case "n"
servoMin = servoMin + 5 max cServoCenter
write eepServoMin,servoMin
case "x"
servoMax = servoMax - 5 min cServoCenter
write eepServoMax,servoMax
case "y"
servoMax = servoMax + 5 max cServoMax
write eepServoMax,servoMax
case "0"
activeSpot = cServoCenter
case "1"
dec activeSpot
case "2"
inc activeSpot
case "3"
activeSpot = activeSpot - 5
case "4"
activeSpot = activeSpot + 5
case "5"
activeSpot = activeSpot - 10
case "6"
activeSpot = activeSpot + 10
case "7"
activeSpot = servoMin
case "8"
activeSpot = servoMax
endselect
activeSpot = activeSpot max servoMax
activeSpot = activeSpot min servoMin
if activeServo = tiltServo then
activeSpot = activeSpot min tiltMin
endif
if activeSpot <> lastspot then
' serout 0,N2400,(#activeServo, " ", #activeSpot)
if activeServo = panServo then
panSpot = activeSpot
else
tiltSpot = activeSpot
endif
gosub servoOut
lastspot = activeSpot
' pause 50
endif
loop
servoOut: ' smoothly move from lastSpot
b2 = activeSpot - lastSpot
b3 = 1
if activeSpot < lastSpot then
b2 = lastSpot - activeSpot
b3 = $FF ' minus one
endif
sertxd("Servo: ",#activeServo," pos: ",#activeSpot, cr,lf)
' serout 0,N2400,(#b2, " ", #b3, " ", #lastSpot, " ", #activeSpot,10,13)
activeSpot = lastSpot
for b4 = 1 to b2 ' move smoothly to new activeSpot
activeSpot = activeSpot + b3
' serout 0,N2400,(#b4, " ", #b3, " ", #b2, " ", #activeSpot,10,13)
pulsout activeServo,activeSpot
pause 20
pulsout activeServo,activeSpot ' twice seems to make it work
pause 20
next b4
lastSpot = activeSpot
return