Advertisement
Midge

Osc_Ex Processing Code

Apr 13th, 2011
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. //OPEN SOUND FROM iPHONE TO ARDUINO VIA SERIAL PORT
  2. //Import libraries
  3. import oscP5.*;
  4. import netP5.*;
  5. import processing.serial.*;
  6.  
  7. OscP5 oscP5;    // create open Sound object
  8. Serial myPort;  // Create Serial object
  9.  
  10. byte byteout=0 ;      // Data to be sent to the serial port
  11.  
  12. void setup()
  13. {
  14.   oscP5 =new OscP5(this,1337); //set up Open Sound listening port (check Port No!)
  15.   size(200, 200);
  16.   println (Serial.list()); //Print list of available Ports
  17.   String portName = Serial.list()[3]; //[3] may differ on your set-up, check Processing console printout
  18.   myPort = new Serial(this, portName, 9600); //set up Arduino serial port
  19.  
  20. }
  21.  
  22. void draw()
  23. {
  24.  
  25. }
  26. // Listen for Open Sound signal
  27.  
  28. void oscEvent(OscMessage theOscMessage) {
  29.  
  30. /* print the address pattern of received OscMessage (see next comment) */
  31.  
  32. println("### received an osc message.");
  33. println(" addrpattern: "+theOscMessage.addrPattern());
  34.  
  35.    
  36. /*Test which pushutton is being pressed and toggle that bit using XOR 1
  37.  
  38. NOTE: The address patterns will obviously be different for your setup, most likely the
  39. '/x/Midges-iPhone' end bit,you'll need to change them.
  40. You'll see them printed in Processing's console when you push the buttons'
  41. */
  42.  
  43. if(theOscMessage.checkAddrPattern("/mrmr/pushbutton/2/Midges-iPhone")==true)
  44. {byteout^=(1<<0);} //Toggle Pin 8
  45. if(theOscMessage.checkAddrPattern("/mrmr/pushbutton/3/Midges-iPhone")==true)
  46. {byteout^=(1<<1);} //Toggle Pin9
  47. if(theOscMessage.checkAddrPattern("/mrmr/pushbutton/4/Midges-iPhone")==true)
  48. {byteout^=(1<<2);} //Toggle Pin 10
  49. if(theOscMessage.checkAddrPattern("/mrmr/pushbutton/5/Midges-iPhone")==true)
  50. {byteout^=(1<<3);} //Toggle Pin 11
  51. println(byteout); //print to console for debugging
  52. myPort.write(byteout); //write Byte to port
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement