Transition of images with LDR
in
Programming Questions
•
8 months ago
Hi...
I want to do the transition of images with respect to the intensity of light strike on LDR.
I manipulate the output of LDR from 1 to 10 and there is 10 images in processing, i want those images in processing to change with respect to the LDR output.
I have code for transition of images without LDR but i can't manipulate it for the LDR.
Here is the code for transition of images
- PImage[] imgs;
- int nbr_of_images, img_no;
- float transitionFrames = 50; // number of frames for transition
- int displayFrames = 250; // number of frames each image shall be displayed
- float fadeValue = 0;
- void setup() {
- size(1440, 900);
- nbr_of_images = 10;
- img_no = 0;
- imgs = new PImage[nbr_of_images];
- imgs[1] = loadImage("img1.JPG");
- imgs[2] = loadImage("img2.JPG");
- imgs[3] = loadImage("img3.JPG");
- imgs[4] = loadImage("img4.JPG");
- imgs[5] = loadImage("img5.JPG");
- imgs[6] = loadImage("img6.JPG");
- imgs[7] = loadImage("img7.JPG");
- imgs[8] = loadImage("img8.JPG");
- imgs[9] = loadImage("img9.JPG");
- imgs[10] = loadImage("img10.JPG");
- }
- void draw() {
- background(255);
- // full opacity for image in background
- tint(255);
- image(imgs[img_no], 0, 0);
- // fade foreground-image using tint()
- tint(255, lerp(0,255,fadeValue));
- image(imgs[(img_no+1)%nbr_of_images], 0, 0);
- // change image and reset fadeValue
- if (frameCount % (displayFrames) == 0){
- img_no = (img_no + 1) % nbr_of_images;
- fadeValue = 0;
- }
- // increase opacity of second image
- fadeValue = fadeValue+1/transitionFrames;
- }
ARDUINO code for LDR
- const int numReadings = 10;
- int readings[numReadings]; // the readings from the analog input
- int index = 0; // the index of the current reading
- int total = 0; // the running total
- int average = 0; // the average
- int inputPin = A0;
- void setup()
- {
- // initialize serial communication with computer:
- Serial.begin(9600);
- // initialize all the readings to 0:
- for (int thisReading = 0; thisReading < numReadings; thisReading++)
- readings[thisReading] = 0;
- }
- void loop() {
- // subtract the last reading:
- total= total - readings[index];
- // read from the sensor:
- readings[index] = analogRead(inputPin);
- // add the reading to the total:
- total= total + readings[index];
- // advance to the next position in the array:
- index = index + 1;
- // if we're at the end of the array...
- if (index >= numReadings)
- // ...wrap around to the beginning:
- index = 0;
- // calculate the average:
- average = total / numReadings;
- // send it to the computer as ASCII digits
- Serial.print(average*10/1023);
- delay(1); // delay in between reads for stability
- }
Any ideas?
Any help is much appreciated!
Any help is much appreciated!
Thanking you in anticipation