Last active
May 5, 2016 17:08
-
-
Save dpentecost/f16189cdee82262f4a4b to your computer and use it in GitHub Desktop.
TouchOSC to Fadecandy via Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* TouchOSCxyPad to Fadecandy Dot Example | |
* | |
* TouchOSC Example displaying values received from | |
* the "Simple" layout (Page3) xyPad | |
* By Mike Cook | |
* http://www.thebox.myzen.co.uk | |
* | |
* Fadecandy Adaptation by Dave Pentecost | |
*/ | |
//Setup OSC Libraries | |
import oscP5.*; | |
import netP5.*; | |
OscP5 oscP5; | |
//Setup Fadecandy (Make sure OPC routines are in a second tab) | |
OPC opc; | |
PImage dot; | |
//TouchOSC display recreation variables | |
boolean xyPadNeedsRedraw = true; | |
float xPad = 120, yPad = 120; | |
int [] xyPadStrip = new int [5]; | |
void setup() { | |
size(290,360); | |
frameRate(25); | |
background(0); | |
/* start oscP5, listening for incoming messages at port 8000 */ | |
oscP5 = new OscP5(this,8000); | |
//Okay, now Fadecandy | |
// Load a sample image - Make sure it is in data folder for this sketch | |
dot = loadImage("dot.png"); | |
// Connect to the local instance of fcserver | |
opc = new OPC(this, "127.0.0.1", 7890); | |
// Map an 8x8 grid of LEDs to the center of the window | |
opc.ledGrid8x8(0, width/2, height/2, height / 12.0, 0, false); | |
} | |
void oscEvent(OscMessage theOscMessage) { | |
String addr = theOscMessage.addrPattern(); | |
// println(addr); // uncomment for seeing the raw message | |
if(addr.indexOf("/3/xy") !=-1){ // the 8 X Y area | |
xPad = (theOscMessage.get(0).floatValue()); | |
yPad = (theOscMessage.get(1).floatValue()); | |
// println(" x = "+xPad+" y = "+yPad); // uncomment to see x & Y values | |
xyPadNeedsRedraw = true; | |
} | |
// Mike has code to listen for other OSC messages in other examples | |
} | |
void draw() { | |
background(0); | |
int x1 = int(xPad*240)+15; | |
int y1 = int(yPad*240)+15; | |
float dotSize = height * 0.4; | |
image(dot, x1 - dotSize/2, y1 - dotSize/2, dotSize, dotSize); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a first stab at TouchOSC control of Fadecandy, in this case for an 8X8 neopixel grid. Note that you will need the OPC file in another tab of this sketch, and will need FC server running. You can find these at https://github.com/scanlime