Transition between windows in GUI builder
in
Contributed Library Questions
•
4 months ago
Hi,
I'm currently working on a project involving serial communication between the G4P GUI builder and an Arduino Uno set. I'm new to both languages and would like some help.
Objective:
I am trying to make a GUI that resembles a typical Powerpoint slideshow- the user presses a physical pushbutton on the Arduino which causes the GUI to transition from one window to the next, much like how a clicker functions in a slideshow presentation.
What I've managed so far
So far, I've been able to establish serial communication between my Arduino and the G4P. I've tried using the "window1.setVisible(false)" method in response to input from the Arduino push button. Sharing my codes below:
Main Sketch Tab
// Need G4P library
import g4p_controls.*;
import processing.serial.*;
Serial port;
String portname = "/dev/tty.usbmodemfd121";
int baudrate = 9600;
int value = 0;
public void setup(){
size(480, 320, JAVA2D);
createGUI();
customGUI();
port = new Serial(this, portname, baudrate);
println(port);
}
// Place your setup code here
public void draw(){
background(230);
while(port.available() > 0){
value = port.read();
serialEvent(value);
}
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){
window1.setVisible(false);
}
GUI Tab
/* =========================================================
* ==== WARNING ===
* =========================================================
* The code in this tab has been generated from the GUI form
* designer and care should be taken when editing this file.
* Only add/edit code inside the event handlers i.e. only
* use lines between the matching comment tags. e.g.
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
// It is safe to enter your event code here
} //_CODE_:button1:12356:
* Do not rename this tab!
* =========================================================
*/
void serialEvent(int serial){
// if serial event is 'H' actVal is increased
if(serial=='H') {
window1.setVisible(true);
}else {
window1.setVisible(false);
}
}
synchronized public void win_draw1(GWinApplet appc, GWinData data) { //_CODE_:window1:990793:
appc.background(230);
} //_CODE_:window1:990793:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
if(frame != null)
frame.setTitle("Sketch Window");
label1 = new GLabel(this, 166, 120, 150, 68);
label1.setText("Press Button to Start");
label1.setOpaque(false);
window1 = new GWindow(this, "Window title", 0, 0, 511, 316, false, JAVA2D);
window1.addDrawHandler(this, "win_draw1");
label2 = new GLabel(window1.papplet, 182, 114, 140, 85);
label2.setText("Press and Hold Button for 10 secs (TBC)");
label2.setOpaque(false);
}
// Variable declarations
// autogenerated do not edit
GLabel label1;
GWindow window1;
GLabel label2;
The result: Window 1 appears when I press the button, but it stays as long as the button is held. Not the effect I was aiming for.
Questions
- How do I achieve the 'slide-transition' effect?
- Is there a way to improve on my serial communication with the Arduino?
- I would like to code for more complicated responses with reference to the Arduino button. How can I go about coding these? For instance,
- Cause the window transition only if user presses and holds the button for 10 secs
- Cause the window transition only if user presses the button 5 times consecutively
Appreciate any advice! Thank you!
1