hi all
i am a beginner to use vb 6 with Arduino
i have a problem to read the data from Arduino and use it to change a picture in vb 6 form
Arduino send to vb program that the output is hi or low then vb program receive this data and
change visibility of the photo true or false ( the name of the picture is onn and off )
it already work but it is changed as you see
can you help me to modify my code to get this result stable
my Arduino code is
int inPin = 2;
int led1 = 6;
int val = 0;
String x = "hi";
String y = "low";
void setup() {
Serial.begin(9600);
pinMode(inPin,INPUT);
pinMode(led1,OUTPUT);
}
void loop()
{
val = digitalRead(inPin);
//Serial.println(val);
delay(100);
if ( val > 0 )
{
digitalWrite(led1, HIGH);
delay(1000);
Serial.print ("");
Serial.println (x);
}
else
{
digitalWrite(led1, LOW);
delay(1000);
Serial.print ("");
Serial.println (y);
}
}
my vb code is
Dim str As String
Dim x As Integer
Private Sub Form_Load()
With MSComm1
.CommPort = 3
.Settings = "9600,N,8,1"
.Handshaking = comRTS
.RTSEnable = True
.DTREnable = True
.RThreshold = 1
.SThreshold = 1
.InputMode = comInputModeText
.InputLen = 0
.PortOpen = True
End With
End Sub
Private Sub Timer1_Timer()
str = MSComm1.Input
Text2.Text = str
If str = hi Then
x = 1
Else
x = 0
End If
If (x = 1) Then
Text1.Text = Val(x)
onn.Visible = True
off.Visible = False
delay = 1000
Else
Text1.Text = Val(x)
onn.Visible = False
off.Visible = True
delay = 1000
End If
End Sub
thanks my frinds