PDA

View Full Version : Controlling servo via visual basic VScrollbar



karabet
02-13-2010, 02:23 PM
Hi,
I’m building a BS2 servo controller via serial port the bS2 script is
' {$STAMP BS2}
' {$PBASIC 2.5}
·counter VAR Byte
·servo VAR Byte
PinNumber VAR Byte
·
SERIN 16,16780,[WAIT(255),PinNumber, servo]
·
FOR counter = 1 TO 150
· PULSOUT PinNumber,servo
· PAUSE 20
NEXT
END
·
I would like to control the servo via Visual basic 6 program but didn’t succeed, can someone help me please. I’m using the VScroollbar· and the VB code is:

Option Explicit
Private Sub Form_Load()
Dim Pins As Long
'· Add the pin numbers 0 to 15 to cboPinNumber
For Pins = 0 To 15
··· cboPinNumber.AddItem CStr(Pins)
Next Pins
' Default to Pin 0 being selected
cboPinNumber.ListIndex = 0
' Default to optState(0) being selected

'· Use COM1
MSComm1.CommPort = 1
' 2400 baud, no parity, 8 data bits, 1 stop bit
MSComm1.Settings = "2400,N,8,1"
' Make sure DTR line is low to prevent Stamp reset
MSComm1.DTREnable = True

' Open the port
MSComm1.PortOpen = True
End Sub
Private Sub VScroll1_Change()
Dim servo As Long
Dim cboPinNumber As Long
Text1.Text = VScroll1.Value
servo = Text1.Text
MSComm1.Output = Chr$(255) & Chr$(cboPinNumber)
MSComm1.Output = Chr$(Text1.Text)
End Sub
Private Sub VScroll1_Scroll()
VScroll1_Change
End Sub
·
Can someone help please is there an example for this subject.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards,

Karabet


Post Edited (karabet) : 2/13/2010 10:14:36 AM GMT

Oper8r Al
02-14-2010, 09:43 PM
Here is a thread that uses visual basic and a bs2. I think a couple of posts down it talks about slider controls to control a servo. Hope this helps.

http://forums.parallax.com/showthread.php?p=671804