i want to control two videos using two capactive sensors but don't get how to relate videos with capacitive sensor's on serial communication,
i want like if i touch "sensor one" then "movie one" will play if touch "sensor two " then first movie stop and "movie two " will play and vice versa. i also want to know the function of serial.print();
Here is my code for arduino....
#include "mpr121.h"
#include <Wire.h>
int irqpin = 2; // Digital 2
boolean touchStates[2]; //to keep track of the previous touch states
void setup(){
pinMode(irqpin, INPUT);
digitalWrite(irqpin, HIGH); //enable pullup resistor
Serial.begin(9600);
Wire.begin();
mpr121_setup();
}
void loop(){
readTouchInputs();
}
void readTouchInputs(){
if(!checkInterrupt()){
Wire.requestFrom(0x5A,2);
byte LSB = Wire.read();
byte MSB = Wire.read();
uint16_t touched = ((MSB << 8) | LSB);
for (int i=0; i < 12; i++){
if(touched & (1<<i)){
if(touchStates[i] == 0){
if(i==0)
{
Serial.print((char)1);
}
if(i==1)
{
Serial.print((char)2);
}
else if(touchStates[i] == 1){
//pin i is still being touched
}
touchStates[i] = 1;
}
}
else{
if(touchStates[i] == 1){
if(i==0)
{
Serial.print((char)0);
}
if(i==1)
{
Serial.print((char)0);
}
touchStates[i] = 0;
}
}
}
}
}
here is my code for processing
import processing.serial.*;
import processing.opengl.*;
import codeanticode.gsvideo.*;
import codeanticode.glgraphics.*;
Serial port;
GSMovie myMovie, myMovie2, nowPlaying;
GLTexture tex;
PImage img;
int val = 0;
void setup() {
size(960, 540, GLConstants.GLGRAPHICS);
background(0);
tex = new GLTexture(this);
myMovie = new GSMovie(this, "looper.mov" );
myMovie2 = new GSMovie(this, "childplay.mov" );
nowPlaying = myMovie;
nowPlaying.loop();
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
}
void draw() {
background(255);
image(nowPlaying,0,0,width,height);
if (0 < port.available()) {
val = port.read();
}
if (val == 1) {
myMovie2.pause();
myMovie2.jump(0);
nowPlaying = myMovie;
nowPlaying.loop();
}
if (val == 2) {
myMovie.pause();
myMovie.jump(0);
nowPlaying = myMovie2;
nowPlaying.loop();
}
}
void movieEvent(GSMovie _mov){
_mov.read();
}
thanxs in anticipation...................