hi!
can you help me please in right coding the arduino and the vb6...i find hard in communicating the two devices which is the arduino and the vb6.
here is my code:
for arduino:
void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(7, OUTPUT);
Serial.begin (9600);
}
void loop()
{
int a = digitalRead (2);
int b = digitalRead (3);
int c = digitalRead (4);
int d = digitalRead (5);
//digitalWrite (7,LOW);
{
if (a == HIGH)
{
digitalWrite (9, HIGH);
Serial.println ("Red is the color of Led/ The pressures value is 20psi");
delay (200);
digitalWrite (7, HIGH);
delay (400);
digitalWrite (7, LOW);
}
else if (a == LOW)
{
digitalWrite (9, LOW);
}
if (b == HIGH)
{
digitalWrite (10, HIGH);
Serial.println ("Green is the color of Led/The pressures value is 40psi");
delay (200);
digitalWrite (7, HIGH);
delay (400);
digitalWrite (7, LOW);
delay (200);
digitalWrite (7, HIGH);
delay (400);
digitalWrite (7, LOW);
}
else if(b==LOW)
{
digitalWrite (10, LOW);
}
if (c == HIGH)
{
digitalWrite (11, HIGH);
Serial.println ("Blue is the color of Led/The pressures value is 60psi");
delay (200);
digitalWrite (7, HIGH);
delay (400);
digitalWrite (7, LOW);
delay (200);
digitalWrite (7, HIGH);
delay (400);
digitalWrite (7, LOW);
delay (200);
digitalWrite (7, HIGH);
delay (400);
digitalWrite (7, LOW);
}
else if (c==LOW)
{
digitalWrite (11, LOW);
}
if (d == HIGH)
{
digitalWrite (12, HIGH);
Serial.println ("Yellow is the color of Led/The pressures value is 80psi");
delay (200);
digitalWrite (7, HIGH);
}
else if (d==LOW)
{
digitalWrite (12, LOW);
}
}
}
here is my vb code:
Option Explicit
Private Sub Form_Load()
With MSComm1
If .PortOpen Then .PortOpen = False
.CommPort = 1
.Settings = "19200,N,8,1"
.DTREnable = True
.RTSEnable = True
.RThreshold = 4
.SThreshold = 3
.PortOpen = True
End With
With Shape1
Shape1.Shape = 3 'Circle
Shape1.Height = 555
Shape1.Width = 555
Shape1.FillColor = vbWhite
Shape1.FillStyle = 0 'Solid
End With
End Sub
Private Sub LEDOn(col As Long)
End Sub
Shape1.FillColor = col
End Sub
Private Sub LEDOff()
End Sub
Shape1.FillColor = vbWhite
End Sub
Private Sub MSComm1_OnComm()
Dim strData As String
Static strBuffer As String
Dim strWords() As String
Dim intPos As Integer
Dim boComplete As Boolean
Select Case MSComm1.CommEvent
Case comEvReceive
strData = MSComm1.Input
strBuffer = strBuffer & strData
Do
intPos = InStr(strBuffer, vbCrLf)
If intPos > 0 Then
strWords = Split(strBuffer, " ")
Select Case UCase(strWords(1))
Case "a"
Call LEDOn(vbRed)
Case "b"
Call LEDOn(vbGreen)
Case "c"
Call LEDOn(vbBlue)
Case "d"
Call LEDOn(vbYellow)
Case Else
Call LEDOff
End Select
If intPos + 2 < Len(strBuffer) Then
strBuffer = Mid(strBuffer, intPos + 2)
Else
strBuffer = ""
boComplete = True
End If
Else
boComplete = True
End If
Loop Until boComplete = True
End Select
End Sub