A program that allows the user to select the serial port "arduino"
in
Core Library Questions
•
11 months ago
Hello,
I want to make a program that allows the user to select the port on which the arduino is connected. The goal is to transfer it ".exe" (which means the user does not touch the code).
I tried to make a little program, I know that does not work, but the idea is there
I want to make a program that allows the user to select the port on which the arduino is connected. The goal is to transfer it ".exe" (which means the user does not touch the code).
I tried to make a little program, I know that does not work, but the idea is there
- import processing.serial.*;
int port number = 0;
Serial myPort; //Class that manages the serial port
boolean ok = false;
boolean establishedConnection = false;
void setup() {
size(500,500);
smooth();
while (!establishedConnection){
text("Have you connected the arduino?",5,10);
while(!ok){} //wait for a response with the keyboard
println("List of ports: \n" + Serial.list());
if(Serial.length == 1) //one port detected
{
myPort = new Serial(this, Serial.list()[port number], 115200);
establishedConnection = true;
}
else if(Serial.length > 1)
{
text("There are" + Serial.length + "ports currently detected, please indicate the correct port",5,20);
while (!establishedConnection){} //wait for a response with the keyboard
}
else {text("There is no port detected",5,20);}
}
}
void keyPressed() {
if (!establishedConnection)
{
switch (key)
{
case ESC:
exit();
break;
case 'y':
ok=true;
break;
case '1':
case '2':
case '3':
case '4':
port number=int(key-'0'); //conversion char to int
establishedConnection = true;
break;
}
}
}
1