I would like to write a GUI in Java, in which there will be a button. Pressing the button will illuminate the diode connected to the Arduino. I'm using the RXTXcomm.jar library.
For now, I wrote code that displays the COM21 port because that's how my Arduino is connected to and opens it. Here's the code:
private String name;
private String portName;
private CommPortIdentifier portIdentifier = null;
private boolean staPort;
private void getPorts () throws PortInUseException {
List <String> list = new ArrayList ();
CommPortIdentifier serialPortId;
Enumeration enumComm;
enumComm = CommPortIdentifier.getPortIdentifiers ();
while (enumComm.hasMoreElements ()) {
serialPortId = (CommPortIdentifier) enumComm.nextElement ();
name = serialPortId.getName ();
if ("COM21" .equals (name)) {
if (serialPortId.isCurrentlyOwned ()) {
System.out.println ("Port is open");
} Else {
serialPortId.open (name, WIDTH);
}
} else {
System.out.println ("error");
}
}
}
I would like to ask how to now ignite a diode connected to eg pin1? What method to use? I use an Arduino Mega. I found a few posts on this subject, unfortunately no specific answer matching my problem. I will be grateful for any help, materials or links.