I'm a beginner~~~~
I use G4P to design a GUI interface to control my Arduino(like a filter, to handle the parameter from my sensor and deliver it to computer).
![屏幕快照 2016-03-09 下午4.56.06 屏幕快照 2016-03-09 下午4.56.06]()
Something like this, people can input the sampling frequency they want and adjust the level of filter.
But the question comes......
This is the Code from G4P(automatic programmed)
I don't know how to use this and get my parameter or the address from the knob,so i can not connect this with Arduino.
For example, people input the 100 sec, i can give this "100" to Arduino and in the right people can adjust the level, from min to max.
public void knob4_turn1(GKnob source, GEvent event) { //CODE:Filter:944770:
println("knob4 - GKnob >> GEvent." + event + " @ " + millis());
} //CODE:Filter:944770:
public void textfield3_change1(GTextField source, GEvent event) { //CODE:textfield3:900916:
println("textfield3 - GTextField >> GEvent." + event + " @ " + millis());
} //CODE:textfield3:900916:
public void button1_click1(GButton source, GEvent event) { //CODE:button1:684909:
println("button1 - GButton >> GEvent." + event + " @ " + millis());
} //CODE:button1:684909:
// 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");
Filter = new GKnob(this, 272, 100, 166, 188, 0.8);
Filter.setTurnRange(210, 330);
Filter.setTurnMode(GKnob.CTRL_ANGULAR);
Filter.setShowArcOnly(true);
Filter.setOverArcOnly(false);
Filter.setIncludeOverBezel(false);
Filter.setShowTrack(true);
Filter.setLimits(0.0, 0.0, 1.0);
Filter.setNbrTicks(10);
Filter.setShowTicks(true);
Filter.setOpaque(false);
Filter.addEventHandler(this, "knob4_turn1");
textfield3 = new GTextField(this, 70, 126, 62, 27, G4P.SCROLLBARS_NONE);
textfield3.setOpaque(true);
textfield3.addEventHandler(this, "textfield3_change1");
label2 = new GLabel(this, 256, 134, 32, 23);
label2.setText("min");
label2.setOpaque(false);
label1 = new GLabel(this, 425, 136, 33, 21);
label1.setText("max");
label1.setOpaque(false);
label3 = new GLabel(this, 129, 127, 33, 22);
label3.setText("Sec");
label3.setOpaque(false);
button1 = new GButton(this, 166, 126, 30, 24);
button1.setText("OK");
button1.setLocalColorScheme(GCScheme.CYAN_SCHEME);
button1.addEventHandler(this, "button1_click1");
}
// Variable declarations
// autogenerated do not edit
GKnob Filter;
GTextField textfield3;
GLabel label2;
GLabel label1;
GLabel label3;
GButton button1;
// Need G4P library
import g4p_controls.;
import processing.serial.;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
PImage img;
int logoX = 310, logoY = 15;
PFont f;
int wordStartX = 120, wordStartY = 230;
int wordStopX = 293, wordStopY = 230;
int wordAbtastX = 70, wordAbtastY = 100;
int wordFilterX = 330, wordFilterY = 100;
int startX = 180, startY = 223;
int stopX = 350, stopY = 223;
int circleSize = 20;
color startColor = color(0, 190, 15);
color stopColor = color(230, 10, 0);
color pressColor = color(100);
boolean startOver = false, stopOver = false;
public void setup(){
size(500, 300);
createGUI();
customGUI();
f = loadFont("Calibri-48.vlw");
img = loadImage("logo.jpg");
smooth();
noStroke();
String portName = Serial.list()[2];
myPort = new Serial(this, portName, 9600);
// Place your setup code here
}
public void draw(){
background(255);
image(img, logoX, logoY, img.width/2, img.height/2);
update(mouseX, mouseY);
if (mousePressed && startOver)
{fill(pressColor);}
else
{fill(startColor);}
ellipse(startX, startY, circleSize, circleSize);
if (mousePressed && stopOver)
{fill(pressColor);}
else
{fill(stopColor);}
ellipse(stopX, stopY, circleSize, circleSize);
textFont(f, 20);
fill(0,65,115);
text("Start", wordStartX, wordStartY);
text("Stop", wordStopX, wordStopY);
text("Abtastfrequenz", wordAbtastX, wordAbtastY);
text("Filter", wordFilterX, wordFilterY);
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){
}
void update(int x, int y) {
if ( overStart(startX, startY, circleSize) ) {
startOver = true;
stopOver = false;
} else if ( overStop(stopX, stopY, circleSize) ) {
stopOver = true;
startOver = false;
} else {
startOver = stopOver = false;
}
}
boolean overStart(int x, int y, int diameter) {
float disX = x - mouseX;
float disY = y - mouseY;
if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
}
boolean overStop(int x, int y, int diameter) {
float disX = x - mouseX;
float disY = y - mouseY;
if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
}`
Help~~~~~