We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have been trying to make an image transistion to another image when a certain amount of light falls on a LDR, and transistions back when that light is not shining on the LDR anymore. However, the piece of code is not working properly. I am new to processing, so there is a good chance that I am doing it completely wrong. It would be lovely if someone could help me achieve the fade in and out! Thanks in advance! Here is a part of my code, and what I have tried to do for the fade:
int transparency = 0;
void setup() {
img = loadImage(imgFileName+"."+fileType);
bla = loadImage("mermaid.jpg");
size(img.width, img.height);
image(img, 0, 0);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(ledPin, Arduino.OUTPUT);
arduino.pinMode(sensorPin, Arduino.INPUT);
}
void draw() {
int analogValue = arduino.analogRead(sensorPin);
println(analogValue);
if (analogValue > 900) {
noTint();
image(bla, 0, 0);
} else {
while (column < width-1) {
img.loadPixels();
sortColumn();
column++;
img.updatePixels();
}
while (row < height-1) {
img.loadPixels();
sortRow();
row++;
img.updatePixels();
}
if (transparency < 255) {
transparency++;
}
tint(255, 255, 255, transparency);
image(img, 0, 0);
//automatically save the image
if (!saved && frameCount >= loops) {
saveFrame(imgFileName+"_"+mode+".png");
saved = true;
}
}
}
Answers
So the values from arduino come in as expected? Then you can use
analogValue
like any other variable from there. Since your code is not complete, here is a simple example that fades an image depending on your mouse-position:i would distinguish between eval the analog signal and doing the fading
meaning: when the signal comes in, set a boolean or int marker state and do a fading (ignoring the signal state is == doFade) afterwards go to a state waitForDefade and when signal comes fade other direction (state == doDefade) then go to state waitForFade