Sternlab | Sequence Control

Sequence Control is an Arduino interface controlled animation system written in Processing. It gives the user the option to pause, frame forward, frame backward, and adjust the speed of the animation.

Sternlab is a collaboration between R. Stern and D. Rocamora, two artists living in New York City.

You may download the project .zip file, which includes the Arduino and Processing sketches as well as a circuit schematic diagram.

Click for Flickr images:
Interface and Applet

Sequence Control schematic

Processing code:

/*
 * Sequence Control
 * Copyright Sternlab 2006.
 * licenced under the Creative Commons Attribution 2.5 license
 * viewable at: http://creativecommons.org/licenses/by/2.5/
 * contact[at]sternlab[dot]org
 *
 * This program animates images and uses an arduino-powered input device to control that animation.
 * More information about this project can be found at sternlab.org.
 */  

import processing.serial.*;
int numFrames = 20;  // The number of frames in the animation
int frame = 0;
int speed = 15;       //initial framerate
PImage[] images = new PImage[numFrames];
Serial port;
String portname = "/dev/cu.usbserial-A3000YYR";  
int baudrate = 9600;
int value = 0;      //for storing intial serial data
String buffer="";   //for buffering up serial data
float value1 = 0.0; //for converting buffered serial data to numbers
int stepper = 1;    //for stepping frames
 
void setup()
{
  size(720, 480);
  key = 'a';
  for(int i=0; i < numFrames; i++) {
    String imageName = "470" + ((i < 10) ? "0" : "") + i + ".jpg";
    images[i] = loadImage(imageName);
  }
    port = new Serial(this, portname, baudrate);
  println(port);
  frameRate(speed);
} 
 
void draw() 
{ 
   while(port.available() > 0){
        value = port.read();
        serialEvent(value);
        //println(value);
    }
    
   frame+=stepper;  
   
  if(frame >= numFrames){
    frame = 0;
  }
  else if(frame < 0){
    frame = numFrames-1; 
  }
  
  image(images[frame], 0, 0);
  //println(speed);
}

void serialEvent(int serial){
    
    if(serial == 'P'){  //pause
       stepper = 0;
    }
    else if(serial == 'R'){  //step frame reverse
       stepper = 0;
       frame--;
    }
    else if(serial == 'F'){  //step frame forward
       stepper = 0;
       frame++;
    }else{
     stepper = 1;   
     if(serial!=10) {  //10 is a line break        
      // add event to buffer
      buffer += char(serial);          
      } 
      else {
      // if serial is line break set set the speed and clear the buffer
      value1 = float(buffer);
      speed = int(value1/9.0 + 1);  
      //println(speed);
      frameRate(speed);
      buffer="";
      }
    }
    println(speed);
}

Arduino code:


/*
 * Sequence Control
 * Copyright Sternlab 2006.
 * licenced under the Creative Commons Attribution 2.5 license
 * viewable at: http://creativecommons.org/licenses/by/2.5/
 * contact[at]sternlab[dot]org
 *
 * This program animates images and uses an arduino-powered input device to control that animation.
 * More information about this project can be found at sternlab.org.
 */
 
int ledPin1 = 5;                 // LED connected to digital pin
int ledPin2 = 6; 
int ledPin3 = 7; 
int ledPin4 = 8; 
int potPin = 5;    // select the input pin for the potentiometer
int val = 0;       // variable to store the value coming from the sensor
int value = 0; 
int lastval = 0;
int pausePin = 2;
int ffPin = 3;
int revPin = 4;
int currentPin;

void setup()
{
  
  pinMode(ledPin1, OUTPUT);      // sets the digital pin as output
  pinMode(ledPin2, OUTPUT);    
  pinMode(ledPin3, OUTPUT);    
  pinMode(ledPin4, OUTPUT);
  pinMode(pausePin, INPUT);
  pinMode(ffPin, INPUT);
  pinMode(revPin, INPUT);
  
  Serial.begin(9600);        // use the serial port to send the values back to the computer
}

void flashLED(int whichPin, int duration){
  digitalWrite(whichPin, HIGH);   // sets the LED on
  delay(duration*2);                  // waits for a second
  digitalWrite(whichPin, LOW);    // sets the LED off
  delay(duration/2);                  // waits for a second
} 
void updateSpeed(){
  value = analogRead(potPin);
  val = 1024 / value + 1;    // read the value from the sensor
  if (val != lastval){
  //Serial.print(" ");
  Serial.println(value);           // print the value to the serial port
  //Serial.print(" ");
  lastval = val;
  }
}

void loop()  {
  if ( digitalRead(pausePin) == 0) {
    Serial.print("P");
      if (!digitalRead(ffPin)){
        Serial.print('F');  
        currentPin++;
      if (currentPin > ledPin4){
       currentPin = ledPin1; 
      }
      flashLED(currentPin, val+20);
      delay(10);
    }
    else if (!digitalRead(revPin)) {
      Serial.print("R");
      currentPin--;
      if (currentPin < ledPin1){
       currentPin = ledPin4; 
      }
      flashLED(currentPin, val+20);
      delay(10);
    }
   else {
    delay(10); 
   }
  }
  else{   
  updateSpeed();
  delay(val);
  flashLED(ledPin1, val);
  currentPin = ledPin1;
  updateSpeed();
  flashLED(ledPin2, val);
  currentPin = ledPin2;
  updateSpeed();
  flashLED(ledPin3, val);
  currentPin = ledPin3;
  updateSpeed();
  flashLED(ledPin4, val);
  currentPin = ledPin4;

  }      
}