Shop OBEX P1 Docs P2 Docs Learn Events
VisualBasic variables — Parallax Forums

VisualBasic variables

davidedavide Posts: 2
edited 2008-06-05 21:46 in BASIC Stamp
Hi everybody!
I'm new in Basic stamp programming. I've read all what I found about serial communications between VisualBasic and Basic Stamp but I didn't find what I'm looking for.

With Visual Basic Express sending values through the serial is easy. With SERIN command is easy reading the values. My problem is the "conversion". I'd like to send an integer from 0 to 200, read it with SERIN, subract 100 and send the pulse to the servo.
I succeeded in sending the values but they're not what I expected. I didn't understand what's happening. Can anybody help me?
Which kind of variable must I set in VB? Dec16, dec4, byte,...? And which kind of variable must I set in Pbasic?
Thanks a lot

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-06-05 21:01
    Somebody said...
    I succeeded in sending the values but they're not what I expected
    So, what did you send and what did you get? The code you used would also be of help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • davidedavide Posts: 2
    edited 2008-06-05 21:46
    Hi. Thanks for your help. This is the code for VB express:

    Public Class Form1
    ··· Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    ······· If Timer1.Enabled = False Then
    ··········· SerialPort1.Open()
    ··········· Timer1.Enabled = True
    ······· Else
    ··········· Timer1.Enabled = False
    ··········· SerialPort1.Close()
    ······· End If
    ··· End Sub

    ··· Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    ······· Dim vel As Int16
    ······· vel = VScrollBar1.Value
    ······· SerialPort1.Write(vel)
    ··· End Sub
    End Class

    And this is the pbasic code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    DEBUG "start"
    pi VAR Word
    DO
    ··· SERIN 16,16780, [noparse][[/noparse]DEC4 pi]
    ··· PULSOUT 13,750-(pi-100)
    ··· PULSOUT 12,750+(pi-100)
    LOOP
    END

    The effect is very strange and absolutely unpredictable. The scrollbar goes from 0 to 100. I know (or I suppose) that it's only a problem in reading the values...
Sign In or Register to comment.