프로세싱과 아두이노 버튼을 이용하여 동영상을 재생시키려 합니다.
간단할 것 같은데 처음 하는거라 어렵게 느껴지네요.
버튼이 눌러지면 검은 배경으로 영상이 멈추어지고 버튼이 떨어지면 영상이 재생되는, 그런 코드를 만들고 싶습니다.
그런데 영상을 멈추고 플레이 시키는 소스를 잘 모르겠습니다.
아두이노
int switchPin = 4;
void setup() {
pinMode(switchPin, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
if (digitalRead(switchPin) == HIGH) {
Serial.write(1);
} else {
Serial.write(0);
}
delay(100);
}
프로세싱
import processing.video.*;
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
Movie theMov;
void setup()
{
size(1920, 1080);
theMov = new Movie(this, "rere.mov");
theMov.loop();
String portName = Serial.list()[0];
myPort = new Serial(this, "COM3", 9600);
}
void movieEvent(Movie theMov)
{theMov.read();}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
}
background(0); // Set background to white
if (val == 1) { // If the serial value is 0,
fill(0); // set fill to black
}
else {
// If the serial value is not 0,
image(theMov, 0, 0); // set fill to light gray
}
}
|