Quantcast
Channel: Arduino - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 747

How to make an image fade to another image when a certain amount of light falls on a LDR?

$
0
0

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;
        }
      }
    }

Viewing all articles
Browse latest Browse all 747

Latest Images

Trending Articles



Latest Images