Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import oscP5.*;
- import netP5.*;
- OscP5 oscP5;
- NetAddress myBroadcastLocation;
- int [] buttons = new int[8];
- void setup() {
- size(400, 400);
- oscP5 = new OscP5(this, 9005);
- myBroadcastLocation = new NetAddress("10.1.130.128", 9004);
- for ( int i = 0; i < 8; i++) {
- buttons[i] = 0;
- }
- }
- void draw() {
- background(0);
- fill(255);
- textSize(12);
- text("press 'c' to connect to server",20,20);
- stroke(255);
- for (int i = 0; i < 8; i++) {
- if ( buttons[i] == 1) {
- fill(255, 0, 0);
- } else {
- fill(0);
- }
- ellipse((i+1) * width/9.0, height/2, 20, 20);
- }
- }
- void keyPressed() {
- OscMessage m;
- if( key == 'c'){
- m = new OscMessage("/connect");
- oscP5.send(m, myBroadcastLocation);
- }else if( key == 'd'){
- m = new OscMessage("/disconnect");
- oscP5.send(m, myBroadcastLocation);
- }
- }
- /* incoming osc message are forwarded to the oscEvent method. */
- void oscEvent(OscMessage theOscMessage) {
- if ( theOscMessage.checkAddrPattern("/button")) {
- int buttonId = theOscMessage.get(0).intValue();
- int val = theOscMessage.get(1).intValue();
- buttons[buttonId] = val;
- // println("button "+ buttonId + " : " + val);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement