Skip to content

Commit

Permalink
Added support for 2 servos to TouchOSC layouts and controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxzin committed Apr 6, 2012
1 parent 6c982b3 commit bc7d9b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions arduino_touchosc_controller/arduino_touchosc_controller.pde
Expand Up @@ -7,11 +7,13 @@ OscP5 oscP5; // Set oscP5 as OSC connection


int redLED = 0; // redLED lets us know if the LED is on or off int redLED = 0; // redLED lets us know if the LED is on or off
int [] led = new int [2]; // Array allows us to add more toggle buttons in TouchOSC int [] led = new int [2]; // Array allows us to add more toggle buttons in TouchOSC
int currentPos = 0; int currentPosA = 0;
int desiredPos = 0; int desiredPosA = 0;
int currentPosB = 0;
int desiredPosB = 0;


void setup() { void setup() {
size(100,100); // Processing screen size size(200,100); // Processing screen size
noStroke(); // We don’t want an outline or Stroke on our graphics noStroke(); // We don’t want an outline or Stroke on our graphics
oscP5 = new OscP5(this,8000); // Start oscP5, listening for incoming messages at port 8000 oscP5 = new OscP5(this,8000); // Start oscP5, listening for incoming messages at port 8000
arduinoPort = new Serial(this, Serial.list()[0], 9600); // Set arduino to 9600 baud arduinoPort = new Serial(this, Serial.list()[0], 9600); // Set arduino to 9600 baud
Expand All @@ -20,28 +22,47 @@ void setup() {
void oscEvent(OscMessage theOscMessage) { // This runs whenever there is a new OSC message void oscEvent(OscMessage theOscMessage) { // This runs whenever there is a new OSC message


String addr = theOscMessage.addrPattern(); // Creates a string out of the OSC message String addr = theOscMessage.addrPattern(); // Creates a string out of the OSC message
if(addr.indexOf("/1/servo") !=-1){ // Filters out any toggle buttons if(addr.indexOf("/1/servoA") !=-1){ // Filters out any toggle buttons
//int i = int((addr.charAt(9) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30 //int i = int((addr.charAt(9) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30
desiredPos = int(theOscMessage.get(0).floatValue()); // Puts button value into led[i] desiredPosA = int(theOscMessage.get(0).floatValue()); // Puts button value into led[i]
// Button values can be read by using led[0], led[1], led[2], etc. // Button values can be read by using led[0], led[1], led[2], etc.

}
else if(addr.indexOf("/1/servoB") !=-1){ // Filters out any toggle buttons
//int i = int((addr.charAt(9) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30
desiredPosB = int(theOscMessage.get(0).floatValue()); // Puts button value into led[i]
// Button values can be read by using led[0], led[1], led[2], etc.
} }
} }


void draw() { void draw() {
background(50); // Sets the background to a dark grey, can be 0-255 background(50); // Sets the background to a dark grey, can be 0-255


if(currentPos != desiredPos) { if(currentPosA != desiredPosA) {
String pos = str(desiredPos); String pos = str(desiredPosA);
println("Moving to position " + pos); println("Moving to position A " + pos);
arduinoPort.write('a');
arduinoPort.write(pos); arduinoPort.write(pos);
arduinoPort.write('.'); arduinoPort.write('.');
currentPos = desiredPos; currentPosA = desiredPosA;
} }


redLED = int(map(desiredPos, 0, 180, 0, 255)); if(currentPosB != desiredPosB) {
String pos = str(desiredPosB);
println("Moving to position B " + pos);
arduinoPort.write('b');
arduinoPort.write(pos);
arduinoPort.write('.');
currentPosB = desiredPosB;
}

redLED = int(map(desiredPosA, 0, 180, 0, 255));
fill(redLED,0,0); // Fill rectangle with redLED amount fill(redLED,0,0); // Fill rectangle with redLED amount
ellipse(50, 50, 50, 50); // Created an ellipse at 50 pixels from the left... ellipse(50, 50, 50, 50); // Created an ellipse at 50 pixels from the left...
// 50 pixels from the top and a width of 50 and height of 50 pixels // 50 pixels from the top and a width of 50 and height of 50 pixels

greenLED = int(map(desiredPosB, 0, 180, 0, 255));
fill(0,greenLED,0); // Fill rectangle with redLED amount
ellipse(150, 50, 50, 50); // Created an ellipse at 50 pixels from the left...
// 50 pixels from the top and a width of 50 and height of 50 pixels
} }


Binary file modified arduino_touchosc_layout.touchosc
Binary file not shown.
Binary file modified arduino_touchosc_layout_ipad.touchosc
Binary file not shown.

0 comments on commit bc7d9b7

Please sign in to comment.