提问者:小点点

处理Arduino串行端口Cp5. listbox


我想创建一个包含串行端口列表的列表框(使用控制器5GUI库):目标是创建一个独立的应用程序,使用处理与Arduino Uno通信,独立于OS我将使用(win,mac或linux),并选择(使用列表框)正确的串行端口与Arduino通信。


共1个答案

匿名用户

ControlP5 cp5 = new ControlP5(this);
ListBox listBox = cp5.addListBox("serialPorts");
Serial serial;
String[] ports = Serial.list();
for (int i=0; i<ports.length; i++) {
    listBox.addItem(ports[i]);
}

void controlEvent(ControlEvent theEvent) {
    if(theEvent.isGroup() && theEvent.name().equals("myList")){
        int val = (int)theEvent.group().value();
        serial = new Serial(this, ports[val], 9600);
    }
}

未经测试,但这是基本思想…