# XY Pad (OSC ) to procesing

**URL:** <https://discourse.processing.org/t/xy-pad-osc-to-procesing/4575>\
**Category:** Libraries\
**Created:** [October 17, 2018, 6:50pm UTC](https://discourse.processing.org/t/xy-pad-osc-to-procesing/4575 "2018-10-17T18:50:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zpyn](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@zpyn](https://discourse.processing.org/u/zpyn)\
**Post date:** [October 17, 2018, 6:50pm UTC](https://discourse.processing.org/t/xy-pad-osc-to-procesing/4575/1 "2018-10-17T18:50:55Z")

</div>

Hi!  
Im a CG animator and Im learning a little of scripting to improve my skills. I was wondering if someone know how to get the x and y values of a XY Pad, using oscP5. ([https://vimeo.com/14734980](https://vimeo.com/14734980))

I don’t have idea of which methods should I need to use to get this result, I started with these lines, but I think that something is missing, in order to separate the x and y and send

```auto
import oscP5.*;
import netP5.*;

OscP5 oscP5;

float posx = 0;
float posy= 0;

void setup() {
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 8000 */
  oscP5 = new OscP5(this, 8000);

  oscP5.plug(this, "positionx", "/1/xy2");
  oscP5.plug(this, "positiony", "/1/xy2");

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [October 18, 2018, 10:46am UTC](https://discourse.processing.org/t/xy-pad-osc-to-procesing/4575/2 "2018-10-18T10:46:14Z")

</div>

Hi! Have you looked at

```
examples/Contributed Libraries/oscP5/oscP5SendReceive

```

? Also, you could first run a test program to see in which format you are actually receiving the data:

```auto
import oscP5.*;
import netP5.*;
  
OscP5 oscP5;
NetAddress self;

void setup() {
  oscP5 = new OscP5(this, 12000); 
  self = new NetAddress("127.0.0.1", 12000);
}

void draw() {
}

void mousePressed() {
  OscMessage msg = new OscMessage("/mouse");  
  msg.add(mouseX);
  msg.add(mouseY);
  oscP5.send(msg, self); 
}

void oscEvent(OscMessage msg) {
  println(msg);
  println(msg.arguments());
}

```

This program prints the message info and arguments to the console. You can use that same program (changing the ports maybe) to see what you receive from your XY pad. Maybe you are receiving two integers, or two floats, or a string…

---

<div class="post-metadata">

**Author:** ![zpyn](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@zpyn](https://discourse.processing.org/u/zpyn)\
**Post date:** [October 18, 2018, 9:26pm UTC](https://discourse.processing.org/t/xy-pad-osc-to-procesing/4575/3 "2018-10-18T21:26:24Z")

</div>

Hey Thanks man! I will try with this code. I look up for this root (examples/Contributed Libraries/oscP5/oscP5SendReceive) in this website?

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [October 18, 2018, 9:39pm UTC](https://discourse.processing.org/t/xy-pad-osc-to-procesing/4575/4 "2018-10-18T21:39:11Z")

</div>

> [@zpyn](#):
>
> I look up for this root (examples/Contributed Libraries/oscP5/oscP5SendReceive) in this website?

The Processing IDE has an `Examples` menu, inside `File`. All the libraries you install normally come with examples, which appear under `Contributed Libraries` inside the `Examples` menu. Processing comes with hundreds of examples for you to learn from.

---

<div class="post-metadata">

**Author:** ![zpyn](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@zpyn](https://discourse.processing.org/u/zpyn)\
**Post date:** [October 23, 2018, 6:30pm UTC](https://discourse.processing.org/t/xy-pad-osc-to-procesing/4575/5 "2018-10-23T18:30:45Z")

</div>

Thanks man! I rebuild my code using your example as a guide 🙂

```auto
import processing.net.*;
import oscP5.*;
import netP5.*;

float x=0;
float y=0;
float xval=0;

OscP5 oscP5;
NetAddress self;

void setup() {
  oscP5 = new OscP5(this, 8000); 
  self = new NetAddress("127.0.0.1", 8000);
}

void draw() {
}

void Pad() {
  OscMessage msg = new OscMessage("/1/xy2");  
  
  oscP5.send(msg, self); 
  float xval= msg.get(0).floatValue(); 
}

void oscEvent(OscMessage msg) {
  println(msg);
  println(msg.arguments());
  println(xval);
}

```

I don’t know why, the script is not saving the float properly, I think that is taking other values instead of the message argument.

Results  
/192.168.1.67:9000 | /1/xy2 ff  
1.0 1.0  
0.0

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [October 23, 2018, 9:29pm UTC](https://discourse.processing.org/t/xy-pad-osc-to-procesing/4575/6 "2018-10-23T21:29:23Z")

</div>

I think I see a bit of confusion here…

```auto
void Pad() {
  OscMessage msg = new OscMessage("/1/xy2");
  oscP5.send(msg, self);

  // even if there's a global xval variable
  // the following line creates a local temporary variable
  // that gets deleted at the end of this function
  float xval= msg.get(0).floatValue();
  // Also, it's reading an osc argument out of a message
  // which was just SENT (instead of reading such an argument
  // from a received message below)
}

void oscEvent(OscMessage msg) {
  println(msg);
  println(msg.arguments());
  // the following line is printing a global variable called xval
  // which probably contains nothing
  println(xval);

  // what you probably want is to place the data received by this
  // function into the global variable xval, like this:
  xval= msg.get(0).floatValue();
  // if you added float at the beginning of the previous line,
  // the variable would be a local variable, and the content lost
  // at the end of this function
}

```

If the concept of local and global variables is not clear, you could check out this tutorial I made:  
[https://funprogramming.org/50-What-are-global-and-local-variables.html](https://funprogramming.org/50-What-are-global-and-local-variables.html)
