# Example connection with MaxMSP

Once you subscribe to the OSC module, the tab is enabled in BCI. The following example demonstrates a connection of EMOTIV BCI with MaxMS&#x50;**,** which is a visual programming language for music and multimedia.

1. Connect a simulated device (create one on EMOTIV Launcher if you don't have. See [Creating a virtual brainwear](https://emotiv.gitbook.io/emotiv-launcher/devices-setting-up-virtual-brainwear-r/creating-a-virtual-brainwear-device)) or an OSC compatible EMOTIV Brainwear®
2. Choose a [training profile](https://emotiv.gitbook.io/emotivbci/training-profiles) to connect to the external device.
3. Select Sending mode: Unicast to Self
4. Set the IP: 127.0.0.1
5. Set the Port: 8000
6. Choose the Data stream you want to connect: Facial expressions, Mental Commands, or Performance Metrics
7. Click Start
8. Open Max MSP, go to File > Package Manager and install CNMAT Externals
9. &#x20;Go to <https://github.com/Emotiv/opensoundcontrol/tree/master> and check the table with OSC Address Patterns&#x20;
10. Create (replicate) the nodes below and change OSC-route according to whichever OSC Pattern you wish to address (in the example image, Facial expressions/Smile) - check table in the previous step for the addresses.
11. Open Processing and go to Sketch > Import Library… > Add Library , search and install oscP5&#x20;
12. Open a new File.
13. &#x20;Import oscP5 to the code and initialize an instance listening to port 12000. Example code (copy and paste in Processing):

    | <p><strong><code>import oscP5.\*;</code></strong><br><strong><code>//OSC receive</code></strong><br><strong><code>OscP5 oscP5;</code></strong><br><strong><code>// This value is set by the OSC event handler</code></strong><br><br><strong><code>float importedValue = 0;</code></strong><br><strong><code>float radius;</code></strong><br><br><br><strong><code>void setup() {</code></strong><br>  <strong><code>size(1200,1000);</code></strong><br><br> <strong><code>// Initialize an instance listening to port 12000</code></strong><br>    <strong><code>oscP5 = new OscP5(this,8500);</code></strong><br><strong><code>}</code></strong><br><br><strong><code>void draw() {</code></strong><br>  <strong><code>background (0);</code></strong><br>  <strong><code>// Scale up imported value</code></strong> <br>  <strong><code>radius = importedValue \* 1000;</code></strong><br><br>  <strong><code>// Display circle at location vector</code></strong><br>  <strong><code>stroke(255);</code></strong><br>  <strong><code>strokeWeight(2);</code></strong><br>  <strong><code>fill(255);</code></strong><br>  <strong><code>ellipse(500,500, radius, radius);</code></strong><br>  <strong><code>println(radius);</code></strong><br><br><strong><code>}</code></strong><br><br><strong><code>void oscEvent(OscMessage theOscMessage) {</code></strong><br>    <strong><code>float value = theOscMessage.get(0).floatValue();</code></strong><br>   <br>   <strong><code>importedValue = value;</code></strong><br><strong><code>}</code></strong></p> |
    | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

14\. Click the Play button and watch the graphics change according to Smile. importedValue is associated with the circle radius.

15\. Open any example code in File > Examples..\
**16.** Associate importedValue with any float variable from any Library to play around. Be sure to:

* **Import oscP5;**

| <p><strong><code>import oscP5.\*;</code></strong><br><strong><code>//OSC receive</code></strong><br><strong><code>OscP5 oscP5;</code></strong><br><strong><code>// This value is set by the OSC event handler</code></strong></p> |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

* **Initialize importedValue (before void setup);**

| **`float importedValue = 0;`** |
| ------------------------------ |

* **Initialize oscP5 (place it inside void setup);**

| <p> <strong><code>// Initialize an instance listening to port 12000</code></strong><br>    <strong><code>oscP5 = new OscP5(this,8500);</code></strong></p> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- |

* **Associate the event with the variable importedValue (place it after void draw);**&#x20;

| <p><strong><code>void oscEvent(OscMessage theOscMessage) {</code></strong><br>    <strong><code>float value = theOscMessage.get(0).floatValue();</code></strong><br>   <br>   <strong><code>importedValue = value;</code></strong><br><strong><code>}</code></strong></p> |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
