How can I play different video clips in Processing depending on sensors in Arduino

edited May 2017 in Arduino

I am creating a project that is like a small Planetarium. I will have capacative sensors (which detect the human body) inside the planets and I want it so that when the planet is touched, a video is played about that planet.

I currently have my arduino code to produce serial values for the sensors, so for example if the 2nd sensor (out of 9 total sensors) was activated it would produce a line of (0,1,0,0,0,0,0,0,0). I also need to make sure the video doesn't stop playing if sensor 2 is deactivated (user takes their hand away from the planet), so I would like it to play the full video even if the sensor goes from 1>0 whilst it is playing. But if another sensor was to be activated, it would play the video associated to that sensor and override the previous video.

Any help would be greatly appreciated, thanks!

I have attached the arduino code below if it is of any use.


#include <CapacitiveSensor.h>

bool debug = true;

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin

CapacitiveSensor   cs_4_3 = CapacitiveSensor(4,3);

CapacitiveSensor   cs_4_5 = CapacitiveSensor(4,5); 

CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);

CapacitiveSensor   cs_4_7 = CapacitiveSensor(4,7);

CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);


void setup()                    
{
  //  cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
Serial.begin(115200);
}

void loop()                    
  {
 long start = millis();

  long total1 =  cs_4_2.capacitiveSensor(4000);

  long total2 =  cs_4_3.capacitiveSensor(4000);

  long total3 =  cs_4_5.capacitiveSensor(4000);

  long total4 =  cs_4_6.capacitiveSensor(4000);

  long total5 =  cs_4_7.capacitiveSensor(4000);

  long total6 =  cs_4_8.capacitiveSensor(4000);



  if(debug)
  {

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing
    Serial.print(total1);      //showing the values for sensor 1
    Serial.print("\t");        //creating a tab between the next value
    Serial.print(total2);      // print sensor output 2
    Serial.print("\t");        //creating a tab between the next value
    Serial.print(total3);      // print sensor output 3
    Serial.print("\t");        //creating a tab between the next value
    Serial.print(total4);      // print sensor output 4
    Serial.print("\t");        //creating a tab between the next value
    Serial.print(total5);      // print sensor output 5
    Serial.print("\t");        //creating a tab between the next value
    Serial.print(total6);    // print sensor output 6

    Serial.println("\t");      //creates another line
  }
  else{

    if (total1 > 150) {
      Serial.print(1, DEC);
      Serial.print(",");
    } 
    else
    {
      Serial.print(0, DEC);
      Serial.print(",");
    }
    if (total2 > 150)
    {
      Serial.print(1, DEC);
      Serial.println(",");
    }
    else
    {
      Serial.print(0, DEC);
      Serial.println(",");
    }
    if (total3 > 150)
    {
      Serial.print(1, DEC);
      Serial.println(",");
    }
    else
    {
      Serial.print(0, DEC);
      Serial.println(",");
    }
    if (total4 > 150)
    {
      Serial.print(1, DEC);
      Serial.println(",");
    }
    else
    {
      Serial.print(0, DEC);
      Serial.println(",");
    }
     if (total5 > 150)
    {
      Serial.print(1, DEC);
      Serial.println(",");
    }
    else
    {
      Serial.print(0, DEC);
      Serial.println(",");
    }
     if (total6 > 150)
    {
      Serial.print(1, DEC);
      Serial.println(",");
    }
    else
    {
      Serial.print(0, DEC);
      Serial.println(",");
    }

  }

  //  delay(10);                             // arbitrary delay to limit data to serial port 
}

Answers

Sign In or Register to comment.