我似乎无法从Arduino的最后一行(连接到coinslot)转移到标签(vb.net)。 arduino的输出结果显示我已经将多少硬币插入硬币中。然后,我必须将arduino输出中的最后一个数字传送到我创建的vb.net程序中的标签。结果是标签显示了arduino输出的所有行。我将在下面发布代码和照片。
Here is the output from arduino
和
Here is the label from my vb.net program (coins inserted)
以下是vb.net中的代码:
Private Sub printdoc_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
Try
For Each port As String In SerialPort.GetPortNames
port = "COM8"
Next
SerialPort1.BaudRate = Val("9600")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
SerialPort1.Open()
Catch ex As Exception
End Try
End Sub
Private Sub SerialPort1_DataReceived(sender As System.Object, e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Label10.Text &= SerialPort1.ReadExisting()
End Sub
以下是arduino中的代码:
#include <LiquidCrystal.h>
volatile int coins = 0;
void setup()
{
Serial.begin(9600);
pinMode (2,INPUT_PULLUP);
attachInterrupt(0, coinInserted, FALLING);
}
void coinInserted()
{
coins = coins + 1;
Serial.println(coins);
}
似乎找不到任何解决方案。有什么建议吗?