This is just a simple visual basic express 2010 application I made borrowing some code from other forum posts. All it does is turn on an LED when a button is pressed, but it took me a long time to figure this out and with this I could make some more complicated applications
Visual basic code:
Imports System.IO.Ports
Public Class Form1
Public s As New SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
s.Close()
s.PortName = "com4" 'will need to change to your port number
s.BaudRate = 9600
s.DataBits = 8
s.Parity = Parity.None
s.StopBits = StopBits.One
s.Handshake = Handshake.None
s.Encoding = System.Text.Encoding.Default 'very important!
s.Open()
s.RtsEnable = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "On" Then
s.Write(Chr(50))
Button1.Text = "Off"
Else
s.Write(Chr(10))
Button1.Text = "On"
End If
End Sub
End Class
Arduino Code:
int SerialValue = 0;
void setup(){
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop(){
SerialValue = Serial.read();
if(SerialValue == 50){
digitalWrite(13, HIGH);
}
if(SerialValue == 10){
digitalWrite(13, LOW);
}
}
Please do feel free to pick holes in my code, let me know of bad practise or unnecessary bits of code