I am working on a racing Simulater Software. I have already made the GUI for assigning custom buttons to the keystrokes of the hardware. I made a dialog window appear when one is pressing the button "red1". The first attempt at compiling after restart is normal. The second time and every time afterwards the button stays pressed and the dialog appears no matter what button I press. This is not intended by me.
It might be good to know that my ultimate goal is to synchronise the Software with the Hardware (when it comes to pressing buttons) and to assign custom buttons to the keystrokes of the hardware via the software.
import controlP5.*;
import static javax.swing.JOptionPane.*;
PFont Font;
ControlP5 controlP5;
static final float startRange = -0.00001;
static final float changeEndRange = 100.0000;
static final float loopEndRange = changeEndRange + 0.0001;
void setup(){
size (500,350);
smooth();
controlP5 = new ControlP5(this);
controlP5.addBang("red1")
.setPosition(50,50)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xffff0000)
.setColorActive(0xff8B0000);
controlP5.addBang("red2")
.setPosition(150,50)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xffff0000)
.setColorActive(0xff8B0000);
controlP5.addBang("blue1")
.setPosition(50,150)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xff00BFFF)
.setColorActive(0xff1E90FF);
controlP5.addBang("blue2")
.setPosition(150,150)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xff00BFFF)
.setColorActive(0xff1E90FF);
controlP5.addBang("green1")
.setPosition(50,250)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xff228B22)
.setColorActive(0xff006400);
controlP5.addBang("green2")
.setPosition(150,250)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xff228B22)
.setColorActive(0xff006400);
controlP5.addKnob("knob2")
.setValue(0)
.setRange(startRange,loopEndRange)
.setValue(0)
.setPosition(375,200)
.setSize(80,80)
.setColorBackground(0x00000000)
.setColorForeground(0xFFFFFF00)
.setColorActive(0xFFFFFF00);
controlP5.addKnob("knob1")
.setValue(0)
.setRange(startRange,loopEndRange)
.setValue(0)
.setPosition(375,70)
.setSize(80,80)
.setColorBackground(0x00000000)
.setColorForeground(0xffff0000)
.setColorActive(0xffff0000);
}
void controlEvent(ControlEvent theEvent) {
/* events triggered by controllers are automatically forwarded to
the controlEvent method. by checking the name of a controller one can
distinguish which of the controllers has been changed.
*/
/* check if the event is from a controller otherwise you'll get an error
when clicking other interface elements like Radiobutton that don't support
the controller() methods
*/
if(theEvent.isController()) {
print("\ncontrol event from : "+theEvent.getController().getName());
if(theEvent.getController().getName()=="red1") {
showMessageDialog(null, "Please assign a keystroke\n"+ "Press any button!\n",
"Important", INFORMATION_MESSAGE);
}
if(theEvent.getController().getName()=="red2") {
}
if(theEvent.getController().getName()=="blue1") {
}
if(theEvent.getController().getName()=="blue2") {
}
if(theEvent.getController().getName()=="green1") {
}
if(theEvent.getController().getName()=="green2") {
}
if(theEvent.getController().getName()=="knob1Red") {
println(", value : "+theEvent.getController().getValue());
float loopKnob1 = +theEvent.getController().getValue();
if(loopKnob1 > changeEndRange){
theEvent.getController().setValue(0);
println("\nloopEndRange:"+loopEndRange);
println("\nchangeEndRange:"+changeEndRange);
}else if(loopKnob1 < 0){
theEvent.getController().setValue(changeEndRange);
println("\nloopEndRange:"+loopEndRange);
println("\nchangeEndRange:"+changeEndRange);
}
}
if(theEvent.getController().getName()=="knob2Yellow") {
println(", value : "+theEvent.getController().getValue());
float loopKnob2 = +theEvent.getController().getValue();
if(loopKnob2 > changeEndRange){
theEvent.getController().setValue(0);
println("\nloopEndRange:"+loopEndRange);
println("\nchangeEndRange:"+changeEndRange);
}else if(loopKnob2 < 0){
theEvent.getController().setValue(changeEndRange);
println("\nloopEndRange:"+loopEndRange);
println("\nchangeEndRange:"+changeEndRange);
}
}
}
}
void draw () {
Font = createFont("Magneto", 17);
textFont(Font);
background(23,15,97); // Hintergrundfarbe r, g ,b
text ("Racing Sim v0.1", 120, 30);
}
User contributions licensed under CC BY-SA 3.0