How to hold an image for a period of time?

edited March 2017 in Arduino

Hello, I'm fairly new to processing but have been doing a lot of research for a project I'm working on and have stumbled across a bit of a problem. What I'm trying to do is retrieve information from an arduino and display it on a map. To an extent I've been successful, I am able to get location image to display on the screen but because there are multiple inputs coming in per second the images flicker. I was wondering how I would be able to get it so that when the data reads positive, the image will show on the screen for more than a single frame. I apologize if this doesn't make very much sense, I can explain further if needed. Below is my code:

import processing.serial.*;
Serial myPort;
int val;
PImage img;
void setup()
{
   size(2592,1944);
   String portName = Serial.list()[0];
   println(Serial.list());
   myPort = new Serial(this, portName, 9600);
   img = loadImage("Bayer (1).jpg");
   frameRate(1500);
}
void draw()
{

   while (myPort.available() > 0)
   {
      val = myPort.read();
      background(img);

      if(val == 1)
      {
        fill(255,0,0);
        rect(900,700,100,100);
      }
      else if(val == 2)
      {
        fill(255,0,0);
        rect(1260,860,100,100);
      }
      else if(val == 3)
      {
        fill(255,0,0);
        rect(740,1060,100,100);
      }
      else if(val == 4)
      {
         fill(255,0,0);
         rect(1120,1240,100,100);
      }
      else
      {

      }


   }
}

Answers

  • the image will show on the screen for more than a single frame.

    Further details required. You want to hold the image for certain frames or you want your application to keep applying updates from received data while holding images for longer times?

    What information is displayed in the map? Could you provide some code showing your approach?

    Kf

  • So I want the application to keep applying updates from the received data and have the image remain on the screen as long as the updates keep coming back positive. So far it keeps updating but the image flickers between the two received messages. I basically want the image to stay on the screen for a longer period while the information is updating so that instead of it flickering it has a solid image while received data is positive.

    The map displays a road intersection and each of the variables that can be received places a red box at various points in the intersection.

    What exactly do you mean code showing my approach? The code from the original post is all I have for processing. I could post the arduino code that's sending the information to processing if that helps?

  • Please format your code. Edit your post, select your code and hit ctrl+o. Also ensure there is an empty line above and below your code.

    Please check @GoToLoop's post in the following link to manage received data from Arduino: https://forum.processing.org/two/discussion/comment/88092/#Comment_88092

    You can draw the image in setup using image(img,0,0); and then all updates are draw in the same image. The information in the image is dispalyed on the image permanently. Now, if you want to hold input data for a specific amount of time (like for 5 secs for example), then you will need to have a list or an array holding your data that you receive and display. In draw, you display the content of the array and then you have a timer that will remove each object in the list at specific time intervals.

    Kf

  • Ok i updated the code so now it should look right. In drawing the image do you mean the image i have for the background? Other than that it's just rectangles that will be appearing and each of those has to be put in a specific location.

    For the last part, how would I use a list for the various positions and data? I apologize I'm fairly new and trying to learn as best I can. Would you be able to give a brief example of this and holding the image for the time interval?

  • Answer ✓

    You can use an array of PVector for positions

    (If you have different items im different positions)

    to avoid flickering you want to use a boolean

    (Or an array of booleans if you have different incoming signal types that you want to connect to different images / rects)

    The boolean is your mental link between signal and rect/image

    When signal comes set the boolean to true

    display the image not when the signal comes but when the boolean is true

    Thus no flickering

    Find a way when to switch off your boolean

    Eg. after 5 seconds

    each new signal restarts this timer

Sign In or Register to comment.