Simple serial/osc control applet taking up 50% of cpu?
in
Contributed Library Questions
•
2 years ago
Hi All, my first post as a newbie.
I developed an applet that controls a Kramer matrix switcher trough serial, and receives OSC from another program.
All works fine, but it takes up 50% of my macbook pro's cpu. I figured out that the serial library could be the cause of this.
Is this normal behaviour for the serial library, or is my coding the cause? Any (optimisation) tips welcome!
Thanks!
- import processing.serial.*;
- import oscP5.*;
- import netP5.*;
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- Serial myPort;
- void setup() {
- oscP5 = new OscP5(this,11111);
- myPort = new Serial(this, Serial.list()[0], 9600);
- delay(1000);
- }
- void draw() {
- }
- void oscEvent(OscMessage theOscMessage) {
- float firstValue = theOscMessage.get(0).floatValue();
- float secondValue = theOscMessage.get(1).floatValue();
- float thirtValue = theOscMessage.get(2).floatValue();
- if (thirtValue == 1) {
- int[] pip = {1, int(firstValue), int(secondValue), 129} ;
- for (int i=0; i< 4; i=i+1){
- myPort.write(pip[i]);
- }
- myPort.clear();
- }
- }
1