Also erstmal danke für eure Antworten. Ich hab jetzt schon einen Teil des Programs geschrieben, komm aber nicht weiter (wieder durch unzulängliche Kenntnis der Sprache Bascom):
Im folgenden Quellcode wird ein Servo (Servotreiber im Copozessor) von verschiedenen Positionen zu nächsten in langsamen Schritten bewegt:
Die Bewegung von 0 nach 100, als auch die von 100 nach 150 funktionieren, weil jeweils die momentane Position kleiner als die zu erreichende Position ist (curr_pos < go_to_pos).Code:$regfile = "m32def.dat" Declare Sub Rnb_servo(byval Servonummer As Byte , Byval Go_to_pos As Byte) $crystal = 8000000 'Quarzfrequenz $baud = 9600 Dim Curr_pos As Byte Dim Go_to_pos As Byte Dim Servo_counter As Byte Dim Steps_to_go As Byte Call Rnb_servo(1 , 0) Curr_pos = 0 Wait 5 '############################################################################### Hauptschleife: Call Rnb_servo(1 , 100) Wait 3 Call Rnb_servo(1 , 150) Wait 3 Call Rnb_servo(1 , 50) Wait 3 Goto Hauptschleife Sub Rnb_servo(byval Servonummer As Byte , Byval Go_to_pos As Byte) If Go_to_pos > Curr_pos Then For Servo_counter = Curr_pos To Go_to_pos Print "#s" ; Chr(servonummer) ; Chr(servo_counter) Waitms 10 Next Servo_counter Elseif Go_to_pos < Curr_pos Then Steps_to_go = Abs(curr_pos - Go_to_pos) For Servo_counter = 0 To Steps_to_go Print "#s" ; Chr(servonummer) ; Chr(curr_pos - Servo_counter) Waitms 10 Next Servo_counter End If Curr_pos = Go_to_pos End Sub End
Beim Schritte von Position 150 nach 50 sollte also der zweite Teil der If-Abfrage in der Subroutine ausgeführt werden. Das Problem liegt jetzt in der Zeile "Print "#s" ; Chr(servonummer) ; Chr(curr_pos - Servo_counter)". Als Fehler wird "Error 31 : Invalid Data Type" angezeigt.
Ich kapier nicht, wie der Fehler zustande kommt. Kann jemand helfen?
mfg
jagdfalke







Zitieren

Lesezeichen