Trigger an image in interactive installation “sensor input cannot be resolved as a variable”

Hello!

So I have managed to sort the code out to trigger an animation this past week, I’ll share that code now. I now need to trigger multiple animations.

Arduino Code:

#include <CapacitiveSensor.h>


CapacitiveSensor Sensor1 = CapacitiveSensor(4, 2); 



long val1;

int pos;
long threshold = 2000;
#define led 13

void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
}

void loop()

{
{

val1 = Sensor1.capacitiveSensor(30);

if (val1 >= threshold){ // comparing sensor read to threshold
Serial.println(1);

}
else { 
  Serial.println(0);
  }
//Serial.println(val);

delay(50);
}

Processing Code:

import processing.serial.*;



import processing.video.*;
Serial myPort;  // Create object from Serial class
int val = 1;    // Data received from the serial port

String inData = "";
int THRESHOLD = 0;
boolean playing = false;
Movie movie;



void setup() {
  
 
 size(1080, 720);
 frameRate(23.98);
 
 //movie refers to animations 
 
 movie = new Movie(this, "transparent.mp4");

 //speed of animations 
 
 movie.speed(1);
 movie.pause();
 

 
 // print serial ports 
 printArray(Serial.list());

// port communication

 String COM1 = Serial.list()[15]; //change the 0 to a 1 or 2 etc. to match your port
 myPort = new Serial(this, COM1, 9600);


}

void movieEvent(Movie movie) {
 movie.read();
}

void draw() {
  
  background(0); 
}

{
  // code for movie - first animation 
  
 if ( myPort.available() > 0) {  // If data is available,
        try { 
           inData = myPort.readStringUntil('\n');
           if ( inData == null ) {
              throw new Exception("Error reading: "+inData);
           }
           else
             inData = inData.trim();
           val = Integer.parseInt(inData);
           if (val > THRESHOLD) { //If the sensor is touched play movie 1
             if (!playing) {
               
               movie.play();       // display movie1 
               playing = true;
             }
             }
             else{
             if (playing) {
               playing = false;
             }
           }
      } catch (Exception ex) {
        //println("Exception:"+ex.toString()+" Data:"+inData);
      }
      //println(">"+inData+" -> "+val+"<");
      println(inData);
 } 


 image(movie, 0, 0, 580, 790);
 
}

MULTIPLE ANIMATION CODE:

Arduino Code:

#include <CapacitiveSensor.h>


CapacitiveSensor Sensor1 = CapacitiveSensor(4, 2); 
CapacitiveSensor Sensor2 = CapacitiveSensor(4,6);       
CapacitiveSensor Sensor3 = CapacitiveSensor(4,8); 


long val1;
long val2;
long val3;
int pos;
long threshold = 2000;
#define led 13

void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
}

void loop()

{
{

val1 = Sensor1.capacitiveSensor(30);

if (val1 >= threshold){ // comparing sensor read to threshold
Serial.println(1);

}
else { 
  Serial.println(0);
  }
//Serial.println(val);

delay(50);
}



{
  
val2 = Sensor2.capacitiveSensor(30);

if (val2 >= threshold){ // comparing sensor read to threshold
Serial.println(2);

}
else { 
  Serial.println(0);
  }
//Serial.println(val);

delay(50);

}


{

val3 = Sensor3.capacitiveSensor(30);

if (val3 >= threshold){ // comparing sensor read to threshold
Serial.println(3);

}
else { 
  Serial.println(0);
  }
//Serial.println(val);

delay(50);
}

}

Processing Code:


import processing.serial.*;



import processing.video.*;
Serial myPort;  // Create object from Serial class
int val1 = 1;    // Data received from the serial port
int val2 = 2;    // Data received from the serial port
int val3 = 3;   // Data received from the serial port
String inData = "";
int THRESHOLD = 0;
boolean playing = false;
Movie movie;
Movie movie1;
Movie movie2;
Movie movie3;


void setup() {
  
 
 size(1080, 720);
 frameRate(23.98);
 
 //movie refers to animations 
 
 movie1 = new Movie(this, "transparent.mp4");
 movie2 = new Movie(this, "Mushroom clouds.mp4");
 movie3 = new Movie(this, "Mouth smoke.mp4");
 
 //speed of animations 
 
 movie1.speed(1);
 movie1.pause();
 
 movie2.speed(1);
 movie2.pause();
 
 movie3.speed(1);
 movie3.pause();
 
 // print serial ports 
 printArray(Serial.list());

// port communication

 String COM1 = Serial.list()[15]; //change the 0 to a 1 or 2 etc. to match your port
 myPort = new Serial(this, COM1, 9600);


}

void movieEvent(Movie movie) {
 movie.read();
}

void draw() {
  
  background(0); 
}
{
  // code for movie1 - first animation 
  
 if ( myPort.available() > 0) {  // If data is available,
        try { 
           inData = myPort.readStringUntil('\n');
           if ( inData == null ) {
              throw new Exception("Error reading: "+inData);
           }
           else
             inData = inData.trim();
           val1 = Integer.parseInt(inData);
           if (val1 > THRESHOLD) { //If the sensor is touched play movie 1
             if (!playing) {
               
               movie1.play();       // display movie1 
               playing = true;
             }
             }
             else{
             if (playing) {
               playing = false;
             }
           }
      } catch (Exception ex) {
        //println("Exception:"+ex.toString()+" Data:"+inData);
      }
      //println(">"+inData+" -> "+val+"<");
      println(inData);
 } 


 image(movie1, 0, 0, 580, 790);
 
}

{

  
  // code for movie2 -  second animation mushroom clouds
  
 if ( myPort.available() > 0) {  // If data is available,
        try { 
           inData = myPort.readStringUntil('\n');
           if ( inData == null ) {
              throw new Exception("Error reading: "+inData);
           }
           else
             inData = inData.trim();
           val1 = Integer.parseInt(inData);
           if (val2 > THRESHOLD) { //If the sensor is touched play movie 2
             if (!playing) {
               
               movie2.play();       // display movie1 
               playing = true;
             }
             }
             else{
             if (playing) {
               playing = false;
             }
           }
      } catch (Exception ex) {
        //println("Exception:"+ex.toString()+" Data:"+inData);
      }
      //println(">"+inData+" -> "+val+"<");
      println(inData);
 } 


 image(movie2, 50, 0, 580, 790);
 
}

{

  
  // code for movie3 -  third animation Mouth smoke
  
 if ( myPort.available() > 0) {  // If data is available,
        try { 
           inData = myPort.readStringUntil('\n');
           if ( inData == null ) {
              throw new Exception("Error reading: "+inData);
           }
           else
             inData = inData.trim();
           val3 = Integer.parseInt(inData);
           if (val3 > THRESHOLD) { //If the sensor is touched play movie 3
             if (!playing) {
               
               movie3.play();       // display movie1 
               playing = true;
             }
             }
             else{
             if (playing) {
               playing = false;
             }
           }
      } catch (Exception ex) {
        //println("Exception:"+ex.toString()+" Data:"+inData);
      }
      //println(">"+inData+" -> "+val+"<");
      println(inData);
 } 


 image(movie3, 100, 0, 580, 790);
 
}