if (int < 10) { Load next image and decrement integer }
in
Programming Questions
•
4 months ago
Hi,
I have this code (which is probably not very well writtern, but works). The code is changing the appearance of an image based on a Light Dependant Resistor that has Serial Data coming through from Arduino. The potentiometer is just changing the effect.
I want it so when the LDR value (ldreffect) is less than 10, it moves onto the next image, but continues to decrement the blur that you can see in the if () {} statement below.
The problem that I am having is that when I want to increment the photo integer by 1, it keeps looping. I still want the blur to loop though.
Any suggestions??
- boolean sketchFullScreen() {
- return true;
- }
- import processing.serial.*;
- Serial myPort;
- String sensorReading="";
- PImage img;
- int blur = 40;
- int poster = 40;
- int effect = 0;
- int photo = 0;
- void setup() {
- myPort = new Serial(this, "/dev/tty.usbmodem1411", 9600);
- myPort.bufferUntil('\n');
- size(1024, 768);
- img = loadImage("image1.jpg"); // Load the original image
- noLoop();
- }
- void serialEvent (Serial myPort){
- sensorReading = myPort.readStringUntil('\n');
- if(sensorReading != null){
- sensorReading=trim(sensorReading);
- }
- String rawserial = sensorReading;
- int[] serialvals = int(split(rawserial, '\t'));
- int ldr = serialvals[0];
- int pot = serialvals[1];
- String sldr = str(ldr);
- String spot = str(pot);
- //println(pot);
- //println(ldr);
- delay(500);
- ldreffect(sldr);
- potchange(spot);
- }
- void draw() {
- image(img, 0, 0);
- if (blur > 40){
- blur = 40;
- } else if(blur < 0){
- blur = 0;
- }
- if (poster < 2){
- poster = 2;
- } else if (poster > 40){
- poster = 40;
- }
- if(effect == 0){
- filter(BLUR, blur);
- redraw();
- } else if(effect == 1){
- //float poster = map(ldrblur, 10, 50, 50, 2);
- //println(poster);
- filter(POSTERIZE, poster);
- redraw();
- } else if(effect == 2){
- //float poster = map(ldrblur, 10, 50, 50, 2);
- //println(poster);
- filter(INVERT);
- redraw();
- } else if(effect == 3){
- //float poster = map(ldrblur, 10, 50, 50, 2);
- //println(poster);
- filter(GRAY);
- redraw();
- } else if(effect == 4){
- //float poster = map(ldrblur, 10, 50, 50, 2);
- //println(poster);
- filter(THRESHOLD);
- redraw();
- } else if(effect == 5){
- //float poster = map(ldrblur, 10, 50, 50, 2);
- //println(poster);
- filter(BLUR, blur);
- redraw();
- }
- }
- void potchange(String potval) {
- int potchange = int(potval);
- effect = potchange;
- //println(effect);
- }
- void ldreffect(String ldrval) {
- //println(ldrval);
- int ldreffect = int(ldrval);
- //blur = ldrblur;
- if (ldreffect < 10) {
- println(photo);
- blur -= 1;
- poster += 1;
- redraw();
- } else if (ldreffect > 10) {
- blur += 1;
- poster -= 1;
- redraw();
- }
- //println(blur);
- }
1