Hi, I’d like to change the background color of the second sketch using buttons from the first one. I get them to talk to each other using mouse click back and forth, but I’m struggling to switch it to a button. I first started it out with just a mousePressed, but want to move it to buttons.
Here’s the code for the first Sketch
import oscP5.*;
import netP5.*;
import interfascia.*;
OscP5 oscP5Location2;
NetAddress location1;
GUIController c1;
IFButton b1, b2;
IFLabel l;
int c =0;
void setup() {
size(400, 400);
c1 = new GUIController (this);
b1 = new IFButton ("Green", 30, 35, 60, 30);
b2 = new IFButton ("Blue", 110, 35, 60, 30);
b1.addActionListener(this);
b2.addActionListener(this);
c1.add (b1);
c1.add (b2);
oscP5Location2 = new OscP5(this, 6001);
location1 = new NetAddress("127.0.0.1", 5001);
}
void draw() {
background(255,c, 0);
}
void mousePressed() {
OscMessage myMessage = new OscMessage("/test");
myMessage.add("Location 2: Transmit");
myMessage.add(mouseX);
oscP5Location2.send(myMessage, location1);
println("Sending message.");
}
void oscEvent(OscMessage theOscMessage, GUIEvent e) {
String incomingHeader = theOscMessage.get(0).stringValue();
//int incomingMouseX = theOscMessage.get(1).intValue();
int incomingButton1 = theOscMessage.get(1).intValue();
if (e.getSource() == b1) {
background(random(255),random(255),random(255));
} else if (e.getSource() == b2) {
background(100, 100, 130);
}
// print out the message
print("OSC Message Received: ");
println(incomingHeader + " " + incomingButton1);
}
This is the second sketch
import oscP5.*;
import netP5.*;
OscP5 oscP5Location1;
NetAddress location2;
int c =0;
void setup() {
size(400, 400);
oscP5Location1 = new OscP5(this, 5001);
location2 = new NetAddress("127.0.0.1", 6001);
}
void draw() {
background(255,c, 0);
}
void mousePressed() {
OscMessage myMessage = new OscMessage("/test");
myMessage.add("Location 1: Transmit");
myMessage.add(mouseX);
myMessage.add(mouseY);
oscP5Location1.send(myMessage, location2);
println("Sending message.");
}
void oscEvent(OscMessage theOscMessage) {
String incomingHeader = theOscMessage.get(0).stringValue();
int incomingMouseX = theOscMessage.get(1).intValue();
if (mousePressed) {
background(random(255),random(255),random(255));
} else {
background(255);
}
// print out the message
print("OSC Message Received: ");
println(incomingHeader + " " + incomingMouseX);
c = incomingMouseX;
}