We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I am trying to get two videos to cross-fade when connected to a Maxbotix LV-MaxSonarEZ0 sensor. It works, but is very choppy.
Here is the code for the arduino:
const int pwPin = 7;
long pulse, inches, cm;
void setup() {
Serial.begin(9600);
}
void loop() {
pinMode(pwPin, INPUT);
pulse = pulseIn(pwPin, HIGH);
inches = pulse / 147;
Serial.write(inches);
delay(500);
}
Processing Code:
import processing.video.*;
import processing.serial.*;
Movie light;
Movie fog;
Serial port;
float val;
void setup() {
size(854, 480);
//videos
light = new Movie(this, "ChathamLighthouse.mp4");
fog = new Movie(this, "SkyFog.mp4");
fog.loop();
light.loop();
//port
port = new Serial(this, Serial.list()[1], 9600);
}
void draw() {
if (0 < port.available()) {
val = port.read();
}
float trans = map(val, 5, 30, 255, 0);
println(trans);
noTint();
image(light, 0, 0, width, height);
tint(255, trans);
image(fog, 0, 0, width, height);
}
void movieEvent(Movie m) {
m.read();
}
Could it be that my graphics card is not powerful enough to for this project? Or is there something in the code that is making it choppy? I am running the program on my Macbook Air. Here are the specs:
MacBook Air (13-inch, Mid 2011); Processor 1.7 GHz Intel Core i5; Memory 4 GB 1333 MHz DDR3; Intel HD Graphics 3000 384 MB.
Answers
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
decoding and scaling two videos at once probably a bit too much for it.
try it without all the arduino stuff and rule that out.
I've tried it mapping the mouseX coordinate to the alpha channel and it works. I think there is too much data coming into the motion sensor to map it directly. Instead, I am trying to set up conditional statements, so when, for example, a person is 20 inches from the video it fades.
However, I don't want it to fade completely, but just make it semi-transparent. Is there a way to increase the alpha channel value, but then get it to stop at particular number like 100?
constrain()
https://processing.org/reference/constrain_.html
It worked — thank you.
However, now I am getting erratic readings from the serial port. It is reading accurately through the Arduino serial monitor, but in processing I get a loop of specific numbers that do not correspond to the sensor. This continues even when I disconnect the Arduino.
Here is the code:
can we have a clue?