处理草图效果很好,我可以从HDD播放视频,并且当PIR运动传感器检测到我的运动时,但实际上我想从PIR运动传感器触发视频或处理草图。我还用Arduino led引脚测试了运动传感器,当PIR传感器检测到运动时,它会闪烁。
如何将这两个草图相互连接,并且可以在“处理”中使用运动传感器播放任何视频文件。 谢谢!
Ardunio
/*
PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 3; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}```
处理
import processing.video.*;
import processing.serial.Serial;
static final int PORT_INDEX = 0, BAUDS = 9600;
String myString;
Movie video;
void setup() {
size(640,480);
video = new Movie(this,"render.mp4");
video.loop();
}
void draw() {
background(0);
image(video,0,0);
println(myString);
}
void serialEvent(final Serial s) {
video.stop();
}
}
void movieEvent(Movie video) {
video.read();
}