What is the speed of repetition of DRAW? Also, is there a way to speed up?

edited August 2017 in Programming Questions

Good morning. nice to meet you.

I am writing this because of the speed of processing draw statements.

I envisioned a program between Arduino and a computer. And we created the program through processing.   As you can see, the SETUP statement runs once when the program starts and the DRAW statement repeats every time.

However, the speed of the DRAW statement is relatively slow, so getting the data from Arduino is a problem.

1) What is the speed of repetition of DRAW?

2) Also, is there a way to speed up?

Please answer fast.

Tagged:

Answers

  • Answer ✓

    60 fps by default, but you can change it using framerate().

    however, that is only a suggested maximum. if your frames take 1/5th of a second to execute you'll only get 5fps no matter how many you ask for.

    i have an inkling that draw() is not your problem, just because you are asking that question.

  • Framerate

    Dear koogs.

    Since I have experimented, the maximum frame rate per second seems to be about 300. Is not there a way to do more than that?

  • Answer ✓

    Serial data is handle by a separate thread. I will think it will process your data if it arrives faster than Processing's current upper limit frame rate. However, it is processing's upper limit which will not allow you to run at the same speed as your thread. Try increasing the frame rate using the frameRate() function to see if you can match to your input data rate.

    You can check this next example. Click to stop updating the canvas to see the difference in the counters. Adjust the framerate in setup to see the difference. it demonstrates that a separate rate can run faster than draw().

    Related to your arduino, I am going to take a wild guess here. When serialEvent gets called, you have to call readBuffer() as many times as possible until the buffer is emptied out. Is this is true, then you do not need to change the frameRate() but you just need to make sure you handle all the data available in the serial buffer.

    Kf

    // INSTRUCTIONS: Click to pause sketch updating
    // INSTRUCTIONS: Change frameRate() to see contrast between counters
    
    int masterCounter;
    
    void setup() {
      size(500, 500);
      textAlign(CENTER, CENTER);
      fill(255);
    
      frameRate(30);
    
      masterCounter=0;
      thread("countNow");
    }
    
    void draw() {
      background(128);
    
      text("Master Counter   ="+masterCounter+"\nProcessing Counter="+frameCount, width/2, height/2);
    }
    
    void countNow() { 
      while (masterCounter<MAX_INT ) {
        masterCounter++;
        delay(1);
      }
    }
    
    void mouseReleased() {
      looping=!looping;
    }
    
  • Dear kfrajer,

    Thread - this is the answer.

    Thank you. I remembered a good idea. This is the right answer.

  • Dear koogs, Dear kfrajer

    I was able to create a measurement program. 10 [kHz] can be measured through the 'thread'.

    Thank you.

Sign In or Register to comment.