Servo seriel anfahren
Hier ein Beispiel wie man
einen Servo per Terminal oder eigener Software
positionieren kann.
Das besondere hierbei , man kann die Position jederzeit , auch
während der Servo dabei ist eine Position
anzufahren , neu senden und es wird diese neue Position angefahren.
Für den Servo wird der Portc.0 benutzt.
Die Positionswerte werden vom Terminal/Software als String gesendet.
Unser Code
würde dann wie folgt aussehen :
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 40
$framesize = 40
$baud = 9600
Config Servos = 1 , Servo1 = Portc.0 , Reload = 10
Config Serialin = Buffered , Size = 5 , Bytematch = 13
config portc.0 = output
waitms 1000
Declare Sub Serial0charmatch()
Dim Alte_position As Byte
Dim Neue_position As Byte
Dim Position_Von As Byte
Dim Position_Nach As Byte
Dim W As Byte
Enable Interrupts
Servo(1) = 150
Alte_position = 150
main:
If Neue_position <> Alte_position Then
If Neue_Position > 74 and Neue_Position < 225 then
Neu:
Position_Nach = Neue_position
Position_Von = Alte_position
Alte_position = Neue_Position
If Position_Nach < Position_Von Then
For W = Position_von To Position_nach Step -1
Servo(1) = W
if Neue_Position <> Alte_Position then
Alte_position = w
goto neu
endif
Waitms 50
Next W
goto main
End If
If Position_Nach > Position_Von Then
For W = Position_Von To Position_Nach
Servo(1) = W
if Neue_Position <> Alte_Position then
Alte_position=w
goto neu
endif
Waitms 50
Next W
goto main
End If
endif
End If
goto main
End
Sub Serial0charmatch()
Local Incoming_data As String * 5
Input Incoming_data Noecho
Neue_position = val(incoming_data)
Incoming_data = ""
End Sub