arduino UNOをプロセッサとして使用する戦闘ロボット用のリモートコントロールを作成しています。処理IDEでArduinoのCOMポートを選択するG4Pのドロップリストを作成する方法
GUIを描画するためにG4Pツールを使用してIDEを処理するには簡単なLEDコントロールを作成しましたが、COMポートはコード内に設定されています。しかし私は、ユーザーがGP4 GUIツールを使って作成したドロップリストを使ってCOMポートを変更できるようにしたい。
は、ここでの主なスケッチです:
import processing.serial.*;
import java.awt.Dimension;
// Need G4P library
import g4p_controls.*;
Serial myPort;
String myText="";
int keyboard;
Dimension minimumSize = new Dimension(500, 50); //Change values for limit
public void setup(){
createGUI();
customGUI();
// Place your setup code here
myPort = new Serial(this, "COM3", 9600);
myPort.bufferUntil('\n');
keyboard = 0;
frame.setTitle("RG LED CONTROL");
PImage titlebaricon = loadImage("myicon.png");
surface.setIcon(titlebaricon);
size(500, 500);
frame.setResizable(true);
frame.setMinimumSize(minimumSize);
frame.setSize(500, 500);
}
public void draw(){
background(255,255,255);
if (keyboard == 1){
if (keyPressed){
if (key=='a' || key=='A'){
myPort.write('1');
}
if (key=='d' || key=='D'){
myPort.write('2');
}
if (key=='s' || key=='S'){
myPort.write('0');
}
}
if (keyPressed == false){
myPort.write('0');
}
}
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){
}
、ここでG4P GUIツールによって生成されたGUIコードです:
public void button4_click1(GButton source, GEvent event) { //_CODE_:button4:739741:
println("button4 - GButton >> GEvent." + event + " @ " + millis());
myPort.write('1');
} //_CODE_:button4:739741:
public void button5_click1(GButton source, GEvent event) { //_CODE_:button5:355171:
println("button5 - GButton >> GEvent." + event + " @ " + millis());
myPort.write('2');
} //_CODE_:button5:355171:
public void button6_click1(GButton source, GEvent event) { //_CODE_:button6:770875:
println("button6 - GButton >> GEvent." + event + " @ " + millis());
myPort.write('0');
} //_CODE_:button6:770875:
public void button7_click1(GButton source, GEvent event) { //_CODE_:button7:243410:
println("button7 - GButton >> GEvent." + event + " @ " + millis());
if (keyboard == 0){
keyboard = 1;
button4.setVisible(false);
button5.setVisible(false);
button6.setVisible(false);
surface.setSize(500, 50);
} else {
keyboard = 0;
surface.setSize(500, 500);
button4.setVisible(true);
button5.setVisible(true);
button6.setVisible(true);
}
} //_CODE_:button7:243410:
public void imgButton1_click1(GImageButton source, GEvent event) { //_CODE_:imgButton1:580878:
println("imgButton1 - GImageButton >> GEvent." + event + " @ " + millis());
} //_CODE_:imgButton1:580878:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch Window");
button4 = new GButton(this, 20, 70, 140, 140);
button4.setText("RED");
button4.setTextBold();
button4.setLocalColorScheme(GCScheme.RED_SCHEME);
button4.addEventHandler(this, "button4_click1");
label2 = new GLabel(this, 20, 20, 300, 30);
label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
label2.setText("RG LED CONTROL");
label2.setTextBold();
label2.setOpaque(false);
button5 = new GButton(this, 340, 70, 140, 140);
button5.setText("GREEN");
button5.setTextBold();
button5.setLocalColorScheme(GCScheme.GREEN_SCHEME);
button5.addEventHandler(this, "button5_click1");
button6 = new GButton(this, 180, 70, 140, 140);
button6.setText("OFF");
button6.setTextBold();
button6.addEventHandler(this, "button6_click1");
button7 = new GButton(this, 340, 10, 140, 30);
button7.setText("KEYBOARD");
button7.setTextBold();
button7.setLocalColorScheme(GCScheme.CYAN_SCHEME);
button7.addEventHandler(this, "button7_click1");
imgButton1 = new GImageButton(this, 130, 230, 250, 250, new String[] { "logo.png", "logo.png", "logo.png" });
imgButton1.addEventHandler(this, "imgButton1_click1");
}
// Variable declarations
// autogenerated do not edit
GButton button4;
GLabel label2;
GButton button5;
GButton button6;
GButton button7;
GImageButton imgButton1;