MA Creative Media Arts

Master By Project: Projector Motion

The projectors motion has been a development of electronics and code based elements worked on throughout this project. The electronics as discussed have thrown me many issues which have been resolved by testing and researching using forums as my main source of insight. Being less experienced with electronic engineering I felt more time needed to spent here making sure the device worked correctly and consistently.

The projectors motion is driven by 4 key parts, electronics, Arduino and Processing and Mapping. The Arduino is a code base hardware application which can be programmed to drive electronic components such as motors, LEDs, pumps etc. In this case, I used them to drive 2 digital servo motors.

Controlling the Arduino was done using another code based application Processing, which can drive graphics, make web requests and many more interactive tasks using various additional libraries. Arduino and processing can be linked together using a library called Firmata. This library allows control of many of Arduinos features within Processing and USB. The reason for this is that I wanted Processing while driving the motor to send OSC (Open Sound Control) signals.

Using OSC signals, requests and interactions can be made to the application listening on the same channel as the OSC. MadMapper (Projection Mapping Application) by listening to OSC signals from Processing can turn on and off different layers and media content in response to this.

Altogether, Processing is the main components between the application allowing them to talk to one another. Processing does all these in a linear fashion. The code below is what I developed and used within the installation. Main points that are significant are.

  • Processing to MadMapper OSC link
  • Processing to Arduino Link
  • Time specific OSC and motor events.
  • Motor rotation direction and decision
  • OSC Control Events

Developing this allowed me to reach into my depth of knowledge using various application linking them together with a common goal which has remained constant throughout.

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
  
void setup() {
  size(640, 360);  // Size should be the first statement
  frameRate(1);
  arduino = new Arduino(this, "/dev/tty.usbmodem1411", 57600);
  arduino.pinMode(3, Arduino.SERVO);
  arduino.pinMode(10, Arduino.SERVO);
  oscP5 = new OscP5("127.0.0.1",12000);
  myRemoteLocation = new NetAddress("127.0.0.1",8001);
}

int rotate = 60;
int rotateDestination = 0;
int rotateDistance = 0;

int piviot = 111;
int piviotDestination = 0;
int piviotDistance = 0;

int time = 1;
int min = 0;
int sec = 119;
boolean motor = false;
boolean action = false;

String oscMessageDesternation = "";

String OSCdesternation;

void draw() {

  sec = sec + 1;
  int n = sec;
  background(0);   // Set the background to black
  println(n);
  if (n == 1){
    OSCcontentOff();
    OSCmessage("/transition_1");
    oscMessageDesternation = "/transition_1";
    rotateDestination = 60;
    piviotDestination = 111 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
    time = 1;
  }
  if (n == 9) {
    OSCcontentOff();
    rotateDestination = 43;
    piviotDestination = 75;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  
  }
  if (n == 10) {
    OSCcontentOff();
    oscMessageDesternation = "/position_1";
    OSCmessage("/position_1");
    time = 1; 
  }
  if (n == 40){
    OSCcontentOff();
    OSCmessage("/transition_2");
    oscMessageDesternation = "/transition_2";
    rotateDestination = 40;
    piviotDestination = 85 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 41){
    OSCcontentOff();
    oscMessageDesternation = "/position_2";
    OSCmessage("/position_2");
    time = 1; 
  }
   if (n == 68){
    OSCcontentOff();
    OSCmessage("/transition_3");
    oscMessageDesternation = "/transition_3";
    rotateDestination = 48;
    piviotDestination = 111 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 69){
    OSCcontentOff();
    oscMessageDesternation = "/position_3";
    OSCmessage("/position_3");
    time = 1; 
  } if (n == 96){
    OSCcontentOff();
    OSCmessage("/transition_4");
    oscMessageDesternation = "/transition_4";
    rotateDestination = 44;
    piviotDestination = 135 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 97){
    OSCcontentOff();
    oscMessageDesternation = "/position_4";
    OSCmessage("/position_4");
    time = 1; 
  }if (n == 120){
    OSCcontentOff();
    OSCmessage("/transition_5");
    oscMessageDesternation = "/transition_5";
    rotateDestination = 39;
    piviotDestination = 113 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 121){
    OSCcontentOff();
    oscMessageDesternation = "/position_5";
    OSCmessage("/position_5");
    time = 1; 
  }
  if (n == 154){
    OSCcontentOff();
    OSCmessage("/transition_6");
    oscMessageDesternation = "/transition_6";
    rotateDestination = 41;
    piviotDestination = 168 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 155){
    OSCcontentOff();
    oscMessageDesternation = "/position_6";
    OSCmessage("/position_6");
    time = 1; 
  }
  if (n == 182){
    OSCcontentOff();
    OSCmessage("/transition_7");
    oscMessageDesternation = "/transition_7";
    rotateDestination = 50;
    piviotDestination = 52 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 183){
    OSCcontentOff();
    oscMessageDesternation = "/position_7";
    OSCmessage("/position_7");
    time = 1; 
  }
    if (n == 214){
    OSCcontentOff();
    OSCmessage("/transition_8");
    oscMessageDesternation = "/transition_8";
    rotateDestination = 46;
    piviotDestination = 100 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 215){
    OSCcontentOff();
    oscMessageDesternation = "/position_8";
    OSCmessage("/position_8");
    time = 1; 
  }
  
    if (n == 248){
    OSCcontentOff();
    OSCmessage("/transition_9");
    oscMessageDesternation = "/transition_9";
    rotateDestination = 50;
    piviotDestination = 120 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 249){
    OSCcontentOff();
    oscMessageDesternation = "/position_9";
    OSCmessage("/position_9");
    time = 1; 
  }
    if (n == 282){
    OSCcontentOff();
    OSCmessage("/transition_10");
    oscMessageDesternation = "/transition_10";
    rotateDestination = 50;
    piviotDestination = 143 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 283){
    OSCcontentOff();
    oscMessageDesternation = "/position_10";
    OSCmessage("/position_10");
    time = 1; 
  }
  if (n == 323){
    OSCcontentOff();
    OSCmessage("/transition_11");
    oscMessageDesternation = "/transition_11";
    rotateDestination = 43;
    piviotDestination = 60 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 324){
    OSCcontentOff();
    oscMessageDesternation = "/position_11";
    OSCmessage("/position_11");
    time = 1; 
  }
  if (n == 357){
    OSCcontentOff();
    OSCmessage("/transition_12");
    oscMessageDesternation = "/transition_12";
    rotateDestination = 35;
    piviotDestination = 151 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
  if (n == 358){
    OSCcontentOff();
    oscMessageDesternation = "/position_12";
    OSCmessage("/position_12");
    time = 1; 
  }
  if (n == 391){
    OSCcontentOff();
    n = 0;
    sec = 0;
    time = 1; 
    rotateDestination = 60;
    piviotDestination = 111 ;
    movement();
    arduino.servoWrite(3, rotate);
    arduino.servoWrite(10, piviot);
  }
}
void NegativeNegative(){
  println("Negative - Negative");
          rotateDistance = (rotateDestination - rotate) / (time);
          piviotDistance = (piviotDestination - piviot) / (time);
          rotate = rotate + rotateDistance; //Potentialy a negative??
          piviot = piviot + piviotDistance;
          action = true;
          time = time - 1;
          println(time);
          fill(0);
          rect(0,0,width,height);
          fill(255);
          rect(10,10,20,20);
          if (time == 0){
            println(time);
            motor = false;
            action = false;
            rect(0,0,width,height);
           }
        
}
void PositiveNegative(){
  println("Positive - Negative");
          rotateDistance = (rotateDestination - rotate) / (time/1);
          piviotDistance = (piviotDestination - piviot) / (time/1);
          rotate = rotate + rotateDistance;
          piviot = piviot + piviotDistance;
          time = time - 1;
          println(time);
          fill(0);
          rect(0,0,width,height);
          fill(255);
          rect(20,20,30,30);
          if (time == 0){
            println(time);
            motor = false;
            action = false;
            rect(0,0,width,height);     
           }
}
void NegativePositive(){
  println("Negative - Positive");
      
          rotateDistance = (rotateDestination - rotate) / (time/1);
          piviotDistance =  (piviotDestination - piviot) / (time/1);
          rotate = rotate + rotateDistance;
          piviot = piviot + piviotDistance;
          time = time - 1;
          if (time == 0){
            println(time);
            motor = false;
            action = false;
            rect(0,0,width,height);
      
           }
         
}
void PositivePositive(){
  println("Positive - Positive");
          rotateDistance = (rotateDestination - rotate) / (time/1);
          piviotDistance =  (piviotDestination - piviot) / (time/1);
          rotate = rotate + rotateDistance;
          piviot = piviot + piviotDistance;
          time = time - 1;
          println(time);
          if (time == 0){
            println(time);
            motor = false;
            action = false;
            rect(0,0,width,height);
            
           }

}

void NegativeRotate(){
  println("Negative Rotation Only");
        
      
          rotateDistance = (rotateDestination - rotate) / (time/1); 
          rotate = rotate + rotateDistance; //Potentialy a negative??
        
          action = true;
          time = time - 1;
          println(time);
          if (time == 0){
            println(time);
            motor = false;
            action = false;
            rect(0,0,width,height);
           
           
         }
}
void PositiveRotate(){
  println("Positive Rotate Only");
      
   
          rotateDistance = (rotateDestination - rotate) / (time/1);
          rotate = rotate + rotateDistance;
        
          time = time - 1;
          println(time);
          
          if (time == 0){
            println(time);
            motor = false;
            action = false;
            rect(0,0,width,height);
         
           }
      
}
void PositivePiviot(){
  println("Positive Piviot Only");
        
        
          piviotDistance =  (piviotDestination - piviot) / (time/1);
          piviot = piviot + piviotDistance;
          
          time = time - 1;
          println(time);
          
          if (time == 0){
            println(time);
            motor = false;
            action = false;
            rect(0,0,width,height);
            
           }
         
}
void NegativePiviot(){
  println("Negative Piviot Only");
      
          
          piviotDistance = (piviotDestination - piviot) / (time/1);
          piviot = piviot + piviotDistance;
        
          time = time - 1;
          println(time);
          
          if (time == 0){
            println(time);
            motor = false;
            action = false;
            rect(0,0,width,height);
            
            
           
         }
}

void OSCmessage(String OSCdesternation) {
  OSCcontentOff();
  OscMessage myMessage = new OscMessage(OSCdesternation);
  myMessage.add(0.00);
  println(myMessage);
  oscP5.send(myMessage, myRemoteLocation); 
}
void OSCcontentOff() {
  println(oscMessageDesternation);
  OscMessage myMessage = new OscMessage(oscMessageDesternation);
  myMessage.add(1.00); /* add an int to the osc message */
  println(myMessage);
  oscP5.send(myMessage, myRemoteLocation); 
}
void movement(){
if ((rotateDestination < rotate) && (piviotDestination < piviot)){
        NegativeNegative();
       }
      if ((rotateDestination > rotate) && (piviotDestination < piviot)){
        PositiveNegative();   
      }
      if (rotateDestination < rotate && piviotDestination > piviot){
        NegativePositive();  
      }
      if ((rotateDestination > rotate) && (piviotDestination > piviot)){
        PositivePositive();
      }
      if ((rotateDestination == rotate) && (piviotDestination > piviot)){
        PositivePiviot();
      } 
      if ((rotateDestination == rotate) && (piviotDestination < piviot)) {
        NegativePiviot();
      }
      if ((rotateDestination < rotate) && (piviotDestination == piviot)){
        PositiveRotate();
       }
      if ((rotateDestination > rotate) && (piviotDestination == piviot)){
        NegativeRotate(); 
      }
      if ((rotateDestination == rotate) && (piviotDestination == piviot)){
        motor = false; 
      }
}