Calling Draw only once?

edited May 2017 in Arduino

Hello, Is there a function in processing besides the control event function and the draw function that allows me to send strings over to an arduino, in the void setup for processing?

The reason I dont want to use draw is because it writes 60 times per second, which overflows the serial connection, and I dont want to wait on a specific event to run the code, I need to write to these servos in the void setup/when I hit the play button in processing.

I was advised to use a noLoop function which only calls draw() function once, by having a serial event function that sends the serial data to the arduino and it calls draw() at the end.

But I kinda need help on making a noLoop function in void setup?

Tagged:

Answers

  • noLoop() is built into processing.

    https://processing.org/reference/noLoop_.html

  • You can use frameRate() to place an upper limit on how many times draw runs per second. You can have a noLoop/redraw tandem call in setup/serialEvent to drive the draw() function. In very special circumstance, you can write to the ardunio and setup a delay in order for the arduino to process any command. You can also have a controlled draw where you get it to execute only at very specific situations.

    You need to remember that Processing's main idea reside in the nature of the setup/draw functions. You need to understand how they really work and use them at your advantage or adapt your code based on their functionality. I have the impression you want to do something your way which goes against the processing nature like having a draw behavior in setup (?).

    Can you explain more about your issue exactly? Are you getting errors? You are not seeing the results you want? Everything is happening to fast?

    Notice in my first paragraph I was assuming you were using the serial class. If you are using firmatta, you might need another approach.

    Kf

  • edited May 2017
    boolean has_run = false;
    
    void draw(){
      // ...
      runs_once();
    }
    
    void runs_once(){
      if(!has_run) return;
      // ...
      has_run = true;
    }
    
  • How would the code for frame rate look like? Basically I only want draw() to run when an event is triggered so it would write to the arduino, instead of writing 60 fps.

  • You could write to your arduino when you receive the event (not tested).

    Kf

  • Can you give me an example of using noLoop(), and redraw when dealing with event handling functions, so draw only writes once the event occurs?

    And I know I could write to the arduino in the event function, but I prefer to do this way instead.

  • edited May 2017

    Can you give me an example of using noLoop(), and redraw when dealing with event handling functions, so draw only writes once the event occurs?

    https://processing.org/reference/noLoop_.html 8)

    the second example uses mousepressed as the enabling event.

  • But there isnt like a slider press or slider relase so how would I do it for sliders, in the lp5 library?

  • lp5 library? what do you mean?

  • edited May 2017

    Its a graphical library for processing that was created by a third party, here is a link to their website: sojamo.de/libraries/controlP5/

    I just need an example with a slider using the noLoop, redraw, and event handling functions.

  • edited May 2017

    @kloud

    ControlP5 needs the draw() function to update their state, including their graphics! You need to understand how draw works and how the serial event is handling the information as it arrives, and how the latter interacts with the former. Instead of writing to your arduino in draw(), you should use a mouse or key event to trigger the writing event. This is a very standard practice. For example, check how it is done using another library, when a client is writing data to a server: https://processing.org/reference/libraries/net/Client_write_.html

    GoTo's previous post is a very standard example used here in the community.

    Kf

Sign In or Register to comment.