I am using a basic VB program to turn a light on and off on my Arduino BT, however it does not seem to be working. I tested the program with my Diecimilia and it worked fine. Im not sure what im doing wrong, please help! Also note that i was able to load the program onto the BT.
Arduino Code:
void setup(){
pinMode(13,OUTPUT);
Serial.begin(9600);
}
void loop(){
int val;
if (Serial.available()) {
delay(100);
while (Serial.available() > 0) {
val=Serial.read();
if(val=='1') { digitalWrite(13,HIGH); }
else if (val=='0') {digitalWrite(13,LOW);
}
}
}
}
VB Code:
mports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "COM14" 'change com port to match your Arduino port
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default 'very important!
End Sub
Private Sub btnOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOn.Click
picOn.Visible = True
SerialPort1.Open()
SerialPort1.Write("1")
SerialPort1.Close()
End Sub
Private Sub btnOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOff.Click
picOn.Visible = False
SerialPort1.Open()
SerialPort1.Write("0")
SerialPort1.Close()
End Sub
End Class