Here is some VB6 code I put together from your code...
I added a text box as Text1 so that you would know what the pressure is
Option Explicit
' this is added to allow the sleep call
Private Declare Sub Sleep Lib "kernel32" ( _
ByVal dwMilliseconds As Long)
Private Sub Form_Load()
With MSComm1
If .PortOpen Then .PortOpen = False
.CommPort = 7 ' *************** YOU MAY NEED TO CHANGE THIS OR ADD MY CODE TO FIND THE COM PORT************************
.Settings = "9600,N,8,1"
.DTREnable = True
.RTSEnable = True
.RThreshold = 4
.SThreshold = 3
.PortOpen = True
End With
End Sub
Private Sub LEDOn(col As Long)
Shape1.BackColor = col
End Sub
Private Sub LEDOff()
Shape1.BackColor = &HFFFFFF
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
Dim mystr As String
Sleep 1000 ' this waits one second between readings from the Arduino
mystr = "" ' set the string to nothing
mystr = MSComm1.Input
intPos = InStr(mystr, "<")
If intPos > 0 Then
Select Case Mid(mystr, 1, 3) ' strip off the CR/LF
Case "<Y>"
Text1.Text = ("The pressures value is 80 psi")
Call LEDOn(&HFFFF&) ' this is in hex
Case "<B>"
Text1.Text = ("The pressures value is 60 psi")
Call LEDOn(&HFF0000) ' this is in hex
Case "<R>"
Text1.Text = ("The pressures value is 20 psi")
Call LEDOn(&HFF&) ' this is in hex
Case "<G>"
Text1.Text = ("The pressures value is 40 psi")
Call LEDOn(&HFF00&) ' this is in hex
Case Else
Call LEDOff
End Select
End If
End Sub
here is the Arduino code I used to send the info to the VB code, based on your code.
I eliminated some of the logic in your rev because I did not know what it did, and I wonder if you did. It seemed to have njot much to do with what you are looking for. You can put it back in is you need it.
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 ("<R>");
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 ("<G>");
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 ("<B>");
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 ("<Y>");
delay (200);
digitalWrite (7, HIGH);
}
else if (d==LOW)
{
digitalWrite (12, LOW);
}
}
}
It works for me... it should work for you... give it a try!