Hi everyone, I am trying to create a simple program in VB.net to toggle an LED on and OFF but am running into some trouble. I am using a serial to TTL serial breakout board from Ebay to connect to the PC's serial port. Here is the code:
here is the VB.net code:
The problem is I have to hit the button multiple times in my VB.net program for the byte to be recognized and therefore the LED to toggle. It is inconsistent, sometime it works right away, other times I have to push the button multiple times, so it seems to me to be some sort of timing issue. Any advice would be greatly appreciated. Thanks in advance.
Code:
#Picaxe 08M2
SetFreq M32
HSerSetup B9600_32, %000
Do
b1 = 1
Do
HSerIn w0
Loop Until b1 = 0
Select Case b0
Case "1" : High c.4
Case "0" : Low c.4
End Select
Loop
Code:
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class frm_SerialComms
Dim WithEvents BLUETOOTH As SerialPort = New System.IO.Ports.SerialPort("COM6", 9600, Parity.None, 8, StopBits.One)
Private Sub btnLEDON_Click(sender As Object, e As EventArgs) Handles btnLEDON.Click
If Not BLUETOOTH.IsOpen = True Then
BLUETOOTH.Open()
End If
BLUETOOTH.Write("1")
End Sub
Private Sub btnLEDOFF_Click(sender As Object, e As EventArgs) Handles btnLEDOFF.Click
If Not BLUETOOTH.IsOpen = True Then
BLUETOOTH.Open()
End If
BLUETOOTH.Write("0")
End Sub
End Class