<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with bufferuntil() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=bufferuntil%28%29</link>
      <pubDate>Sun, 08 Aug 2021 14:51:13 +0000</pubDate>
         <description>Tagged with bufferuntil() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedbufferuntil%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>no Graph with data from Arduino?</title>
      <link>https://forum.processing.org/two/discussion/14060/no-graph-with-data-from-arduino</link>
      <pubDate>Fri, 18 Dec 2015 12:30:24 +0000</pubDate>
      <dc:creator>hb9bqb</dc:creator>
      <guid isPermaLink="false">14060@/two/discussions</guid>
      <description><![CDATA[<p>tried a simple example to draw a Graph from arduino data. No graph visible? Running on Windows 10</p>

<p>import processing.serial.*;</p>

<p>Serial myPort;        // The serial port
 int xPos = 0;         // horizontal position of the graph</p>

<p>void setup () {
 // set the window size:
 size(400, 600);</p>

<p>// List all the available serial ports
 println(Serial.list());</p>

<p>// open Serial.list()[0].
 // Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[1], 9600);
// myPort = new Serial(this, "COM8", 9600);</p>

<p>// don't generate a serialEvent() unless you get a newline character:
 myPort.bufferUntil('\n');
 // set inital background:
 //background(0);  schwarzer Hintergrund
 background (100,100,255);
 }
 void draw () {
 // everything happens in the serialEvent()
 }</p>

<p>void serialEvent (Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');</p>

<p>if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // convert to an int and map to the screen height:
 float inByte = float(inString);</p>

<p>inByte = map(inByte, 0, 1023, 0, height);
println(inString);  // to see if datas are incoming</p>

<p>// draw the line:
 stroke(0,0,0);
 line(xPos, height, xPos, height - inByte);</p>

<p>// at the edge of the screen, go back to the beginning:
 if (xPos &gt;= width) {
 xPos = 0;
 background(0); 
//background (216,225,165);
 } 
 else {
 // increment the horizontal position:
 xPos++;
 }
 }
 }</p>
]]></description>
   </item>
   <item>
      <title>Error, disabling serialEvent()</title>
      <link>https://forum.processing.org/two/discussion/28124/error-disabling-serialevent</link>
      <pubDate>Sat, 22 Sep 2018 19:34:23 +0000</pubDate>
      <dc:creator>laptophead</dc:creator>
      <guid isPermaLink="false">28124@/two/discussions</guid>
      <description><![CDATA[<p>The full message I am getting is: Error, disabling serialEvent() for /dev/cu.usbmodem2574541
null</p>

<p>The sketch will get the data one time than it hangs on this message.</p>

<p>Here is my code;   I am getting the data from an arduino teensy 3.5
Please help.</p>

<p>Thanks</p>

<p>import processing.serial.*;
Serial port;
int BaseEncGlobal;
int ElbowEncGlobal;
int ShoEncGlobal;
int VertRotEnc;
int HorRotEnc;
int GripEncGlobal;</p>

<p>double X_axis;
double Y_axis;
double Z_axis;
double GripAngle;</p>

<p>String data;
boolean newData = false;</p>

<p>PFont font;</p>

<p>void setup()
{
  size(1280,800);
  //port =  new Serial(this, "/dev/cu.usbserial-A50285BI", 115200);
  port =  new Serial(this, "/dev/cu.usbmodem2574541", 115200);
  port.bufferUntil('\n'); 
  font = loadFont("AgencyFB-Bold-200.vlw");
  textFont(font, 40);
}</p>

<p>void draw()</p>

<p>{ if (newData == true) {</p>

<p>int spaceDown = 55;
  background(0,0,0);
  fill(46, 209, 2);
  text(BaseEncGlobal, 70, spaceDown);
  fill(0, 102, 153);
  text(ShoEncGlobal, 70, spaceDown<em>2);
  fill(0, 102, 153);
 text(ElbowEncGlobal, 70, spaceDown</em>3);
  fill(0, 102, 153);
 text(VertRotEnc, 70, spaceDown<em>4);
  fill(0, 102, 153);
text(HorRotEnc, 70, spaceDown</em>5);
  fill(0, 102, 153);
  text( GripEncGlobal, 70, spaceDown*6);</p>

<p>text(Double.toString(X_axis/10), 270, spaceDown );
newData =false;
}</p>

<p>}</p>

<p>void serialEvent (Serial port)
{</p>

<p>data = port.readStringUntil('\n');
 if (data != null)
 {
 data = trim(data);</p>

<p>int[] nums = int(split(data, ','));
 BaseEncGlobal =  nums [1];
 ShoEncGlobal  =  nums [2];
 ElbowEncGlobal =  nums [3];
 VertRotEnc    =  nums [4];
 HorRotEnc     =  nums [5];
 GripEncGlobal =  nums [6];
 X_axis =  nums [7];
  Y_axis =  nums [8];
   Z_axis =  nums [9];
    GripAngle =  nums [10];
 //println(Double.toString(X_axis/10));</p>

<p>println(data);</p>

<p>newData = true;
 }</p>

<p>}</p>

<p>/*</p>

<p>void serialEvent (Serial port)
{
  data = port.readStringUntil('.');
  data = data.substring(0, data.length() - 1);</p>

<p>// look for the comma between Celcius and Farenheit
  index = data.indexOf(",");
  // fetch the C Temp
  temp_c = data.substring(0, index);
  // fetch the F Temp
  //temp_f = data.substring(index+1, index);
  temp_f = data.substring(1, data.length());</p>

<pre><code>ElbowEncGlobal =  getValue(data, ',', 2);
</code></pre>

<p>}
*/</p>
]]></description>
   </item>
   <item>
      <title>Processing (image display) via Arduino ultrasonic sensor</title>
      <link>https://forum.processing.org/two/discussion/28055/processing-image-display-via-arduino-ultrasonic-sensor</link>
      <pubDate>Thu, 14 Jun 2018 12:33:26 +0000</pubDate>
      <dc:creator>komats</dc:creator>
      <guid isPermaLink="false">28055@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I am just starting to explore posibilities to make something work in processing via arduino (sensors). On school exhibition I want to make a <strong>picture display that shows one image at the time on the wall (with a projector), depending how close or far person is located from distance sensor.</strong>
This is a sketch of what I am thinking about:<img src="https://forum.processing.org/two/uploads/imageupload/088/QJY2PU3L5TTS.jpg" alt="example" title="example" />
To see if it really works, I explored some tutorials that explains how to connect Arduino input with Processing. Currently, I have these codes in both programs:
<strong>for Arduino:</strong></p>

<pre><code>const int anPin1 = 0;
long distance1;

void setup() {
  Serial.begin(9600);  // sets the serial port to 9600
}

void read_sensors(){
  /*
  Scale factor is (Vcc/512) per inch. A 5V supply yields ~9.8mV/in
  Arduino analog pin goes from 0 to 1024, so the value has to be divided by 2 to get the actual inches
  */
  distance1 = analogRead(anPin1)/2;
}

void print_all(){
  /*
  Serial.print("S1");
  Serial.print("inches");
  */
  Serial.print(" ");
  Serial.print(distance1);
  Serial.println();
}

void loop() {
  read_sensors();
  print_all();
  delay(50); 
}
</code></pre>

<p><strong>And for Processing:</strong></p>

<pre><code>import processing.serial.*;  
Serial myPort;  
String data="" ;
PFont  myFont;  
int distance;

void setup(){
  size(1366,900); // size of processing window
  //background(0);// setting background color to black

  myPort = new Serial(this, "/dev/cu.usbmodemfd111", 9600);
  myPort.bufferUntil('\n');
}

void draw(){

  background(0);
  textAlign(CENTER);
  fill(255);
  text(data,820,400);
  textSize(100);
  fill(#4B5DCE);
  text("              Distance :        cm",450,400);
  noFill();
  stroke(#4B5DCE);

}

void serialEvent(Serial myPort){

  data=myPort.readStringUntil('\n');

}
</code></pre>

<p>And this distance reading works perfect!</p>

<p>Unfortunately didn’t found any specific example for what i am looking for.
So the question is, <strong>how can I get, for example, 3 pictures working this way:</strong></p>

<pre><code>if(distance&gt;60){
image(photo1, 0, 0); //display first photograpgy
}
else if (40&lt;distance&lt;60) {
image(photo2, 0, 0);
}
else if (distance&lt;40) {
image(photo3, 0, 0);
}
</code></pre>

<p>Do I have to write something like that in draw ()?
And how can I get income distance value as number from which depends displayed image?
And should I upload any specific library for this?
Do i have to write something also again in Arduino code?</p>

<p>Would be great if someone could suggest any examples or codes for this.</p>

<p>Hoping for advise,
komats!!</p>
]]></description>
   </item>
   <item>
      <title>Collision detection between 2 objects with an ultrasonic sensor (Arduino)</title>
      <link>https://forum.processing.org/two/discussion/27682/collision-detection-between-2-objects-with-an-ultrasonic-sensor-arduino</link>
      <pubDate>Tue, 03 Apr 2018 15:35:25 +0000</pubDate>
      <dc:creator>120898</dc:creator>
      <guid isPermaLink="false">27682@/two/discussions</guid>
      <description><![CDATA[<p>So I'm working from the code in Step 6 (I will attach below) of this tutorial: <a href="http://www.instructables.com/id/How-to-control-a-simple-Processing-game-with-Ardui/" target="_blank" rel="nofollow">http://www.instructables.com/id/How-to-control-a-simple-Processing-game-with-Ardui/</a></p>

<p>I am using an HR-SR04 ultrasonic sensor to control the plane, moving it up and down via hand movements.</p>

<p>What I am trying to do is implement an obstacle feature to the game, by having the score decrease by 1 when the plane hits a cloud. However I can't get the collision detection working for when the plane hits a cloud. The original author has managed to get this working perfectly for when the plane hits the bird but I'm not sure how to get it working between the plane and clouds, I've tried everything I can think of but I'm stuck.</p>

<p>Any help would be appreciated.</p>

<p>Below is the code that I'm working from:</p>

<pre><code>`//Ultrasound plane, a game with a plane and an ultrsound sensor (but

//by Yoruk for Instructables

//send commments or questions to Yoruk16_72 AT yahoo DOT fr


//19 07 14 : initial code
//20 07 14 : it works with arduino !!
//07 07 15 : picture for the plane and for the grass
//06 12 15 : score system with the bird


int i, j; 

int Score ;
float DistancePlaneBird;


float Hauteur; //en Y
float Angle;
int DistanceUltra;
int IncomingDistance;
//float Pas; //pour deplacements X

float BirdX;
float BirdY;

float GrassX ;  //for X position




String DataIn; //incoming data on the serial port

//5 a 32 cm


float [] CloudX = new float[6];
float [] CloudY = new float[6];

//vitesse constante hein


PImage Cloud;
PImage Bird;
PImage Plane;
PImage Grass;



// serial port config
import processing.serial.*; 
Serial myPort;    



//preparation
void setup() 
{

    myPort = new Serial(this, "/dev/cu.usbmodem1411", 9600); 

    myPort.bufferUntil(10);   //end the reception as it detects a carriage return

    frameRate(30); 

    size(800, 600);
    rectMode(CORNERS) ; //we give the corners coordinates 
    noCursor(); //why not ?
    textSize(16);

    Hauteur = 300; //initial plane value


    Cloud = loadImage("cloud.png");  //load a picture
    Bird = loadImage("bird.png");  
    Plane = loadImage("plane.png");  //the new plane picture

        Grass = loadImage("grass.png");  //some grass


    //int clouds position
    for  (int i = 1; i &lt;= 5; i = i+1) {
        CloudX[i]=random(1000);
        CloudY[i]=random(400);
    }


    Score = 0;
}


//incoming data event on the serial port


void serialEvent(Serial p) { 
    DataIn = p.readString(); 
    // println(DataIn);

    IncomingDistance = int(trim(DataIn)); //conversion from string to integer

    println(IncomingDistance); //checks....

    if (IncomingDistance&gt;1  &amp;&amp; IncomingDistance&lt;100 ) {
        DistanceUltra = IncomingDistance; //save the value only if its in the range 1 to 100     }
    }
}


//main drawing loop
void draw() 
{
    background(0, 0, 0);
    Ciel(); //draw the sky
    fill(5, 72, 0);



    //rect(0, 580, 800, 600); //some grass

    //new grass : 

    for  (int i = -2; i &lt;= 4; i = i+1) {  //a loop to display the grass picture 6 times

        image(Grass, 224*i  + GrassX, 550, 224, 58);  // 224 58 : picture size
    }

    //calculates the X grass translation. Same formulae than the bird
    GrassX = GrassX  -  cos(radians(Angle))*10;

    if (GrassX &lt; -224) {  //why 224 ? to have a perfect loop
        GrassX=224;
    }


    text(Angle, 10, 30); //debug things...
    text(Hauteur, 10, 60); 


    //new part : check the distance between the plane and bird and increase the score
    DistancePlaneBird = sqrt(pow((400-BirdX), 2) + pow((Hauteur-BirdY), 2)) ;

    if (DistancePlaneBird &lt; 40) {
        //we hit the bird   
        Score = Score+ 1;

        //reset the bird position
        BirdX = 900;
        BirdY = random(600);
    }

    //here we draw the score
    text("Score :", 200, 30); 
    text( Score, 260, 30); 



    //Angle = mouseY-300; //uncomment this line and comment the next one if you want to play with the mouse
    Angle = (18- DistanceUltra)*4;  // you can increase the 4 value...



    Hauteur = Hauteur + sin(radians(Angle))*10; //calculates the vertical position of the plane

    //check the height range to keep the plane on the screen 
    if (Hauteur &lt; 0) {
        Hauteur=0;
    }

    if (Hauteur &gt; 600) {
        Hauteur=600;
    }

    TraceAvion(Hauteur, Angle);

    BirdX = BirdX - cos(radians(Angle))*10;

    if (BirdX &lt; -30) {
        BirdX=900;
        BirdY = random(600);
    }

    //draw and move the clouds
    for  (int i = 1; i &lt;= 5; i = i+1) {
        CloudX[i] = CloudX[i] - cos(radians(Angle))*(10+2*i);

        image(Cloud, CloudX[i], CloudY[i], 300, 200);

        if (CloudX[i] &lt; -300) {
            CloudX[i]=1000;
            CloudY[i] = random(400);
        }
    }

    image(Bird, BirdX, BirdY, 59, 38); //displays the useless bird. 59 and 38 are the size in pixels of the picture
}


void Ciel() {
    //draw the sky

    noStroke();
    rectMode(CORNERS);

    for  (int i = 1; i &lt; 600; i = i+10) {
        fill( 49    +i*0.165, 118   +i*0.118, 181  + i*0.075   );
        rect(0, i, 800, i+10);
    }
}


void TraceAvion(float Y, float AngleInclinaison) {
    //draw the plane at given position and angle

    noStroke();
    pushMatrix();
    translate(400, Y);
    rotate(radians(AngleInclinaison)); //in degres  ! 


    /*
    Drawing concept :  ;-)

     |\___o__
     ________&gt;     

     */

    scale(0.5);  //0.2 pas mal

    //unless drawing the plane "by hands", just display the stored picture instead. Note that the parameters 2 and 3 are half the picture size, to make sure that the plane rotates in his center.
    image(Plane, -111, -55, 223, 110); // 223 110 : picture size



    popMatrix(); //end of the rotation matrix
}

//file end`
</code></pre>
]]></description>
   </item>
   <item>
      <title>Android Mode - Serial Communication - Andruino</title>
      <link>https://forum.processing.org/two/discussion/26750/android-mode-serial-communication-andruino</link>
      <pubDate>Sat, 10 Mar 2018 06:42:09 +0000</pubDate>
      <dc:creator>Gwak</dc:creator>
      <guid isPermaLink="false">26750@/two/discussions</guid>
      <description><![CDATA[<p>Hi, nice to meet you.</p>

<h1>I want  (Arduino) ------- (Smartphone)   Serial connection.</h1>

<blockquote class="Quote">
  <p>Processing 3.2.1.
  Android Mode 3.0.1</p>
</blockquote>

<h1> &gt; API 6.0</h1>

<p>======================================================================</p>

<pre><code>import io.inventit.processing.android.serial.*; //ANDROID

Serial myPort;      
String inString=""; 

void setup() {

  myPort = new Serial(this, Serial.list(this)[0], 38400); 
  myPort.bufferUntil(10);
}

//===========INCOMING DATA FROM THERMOSTAT=============
void serialEvent(Serial myPort) { 


  try {
    inString = myPort.readString();

  }
  catch(RuntimeException e) {

  }


}
</code></pre>

<p>======================================================================
**Error msg : **</p>

<h1>Processing - Android USB Serial Error.</h1>

<p><img src="https://forum.processing.org/two/uploads/imageupload/269/0N2C6IJ7564V.jpg" alt="Q" title="Q" /></p>
]]></description>
   </item>
   <item>
      <title>table values Arduino</title>
      <link>https://forum.processing.org/two/discussion/26136/table-values-arduino</link>
      <pubDate>Sat, 27 Jan 2018 08:47:28 +0000</pubDate>
      <dc:creator>brugola</dc:creator>
      <guid isPermaLink="false">26136@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm a processing pivot.
I have a problem
 I have a value taken from Arduino, and I visualize it in a graph, but I would also like to be able to visualize it through a numerical table. 
 How can I do?
thank you!</p>

<pre><code>import processing.serial.*;
import grafica.*;
Serial myPort;    // The serial port: 
float val;//i datiricevutidalla porta seriale
int xPos=0;
//Stringa di input dalla porta seriale:
int lf = 10;      // ASCII linefeed 
 GPlot plot1, plot2;





void setup() {
  size(440, 520);
 // Create the first plot  Crea il primo grafico
  plot1 = new GPlot(this);
  plot1.setPos(0, 0);
  plot1.setMar(0, 100, 0,100);
  plot1.setDim(300, 300);
  plot1.setAxesOffset(4);
  plot1.setTicksLength(4);

  // Create the second plot with the same dimensions 
  //Crea il secondo grafico con le stesse dimensioni
  plot2 = new GPlot(this);

  // Prepare the points Prepara i punti
  int val =0;
  GPointsArray points = new GPointsArray(val);

  for (int i = 15; i &lt; 13; i++) {
    points.add(i, 20 + 10*noise(i*0.1));
    if(xPos==13){

    }
  }  

  // Set the points, the title and the axis labels 
  // Imposta i punti, il titolo e le etichette degli assi
  plot1.setPoints(points);
  plot1.setTitleText("Temperature");
  plot1.getYAxis().setAxisLabelText("MASSA ARIA (?)");
  plot1.getXAxis().setAxisLabelText("APERTURA VALVOLA (mm)");


  plot1.activatePanning();
    myPort = new Serial(this, "com3", 9600);
  myPort.bufferUntil(lf);

}




void draw() {
  background(255);
  println(val);
  fill(0);
  text("val  "+val,200,450);
 //Disegna la prima trama 
  plot1.beginDraw();
  plot1.drawBox();
  plot1.drawXAxis();
  plot1.drawYAxis();
  plot1.drawTitle();
 //plot1.drawPoints();//pallinorosso sul valore
  plot1.drawGridLines(GPlot.BOTH);
  plot1.drawLines();
  plot1.endDraw();
  }




  void serialEvent (Serial myPort) {
      //  // get the ASCII string:
  //  // ottiene la stringa ASCII: 
   String inString = myPort.readStringUntil('\n');

    if (inString != null) {
  //    // trim off any whitespace:

      inString = trim(inString);

     val = float(inString);
    println(val);
   }
  }

void mousePressed(){
   GPoint lastPoint = plot2.getPointsRef().getLastPoint();

  if (lastPoint == null) {

       plot1.addPoint(xPos, +val, "(" + str(xPos) + " , " + str(val) + ")");

  } 
  else if (!lastPoint.isValid() || sq(lastPoint.getX() - xPos) + sq(lastPoint.getY() + val) &gt; 2500) {

  }

  if( mouseButton == LEFT ) xPos+=1; 

  fill(0);
   text ("val"+val,200,480);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to perform a conditional check in processing on a value from serial read from arduino</title>
      <link>https://forum.processing.org/two/discussion/26127/how-to-perform-a-conditional-check-in-processing-on-a-value-from-serial-read-from-arduino</link>
      <pubDate>Fri, 26 Jan 2018 14:14:34 +0000</pubDate>
      <dc:creator>heaversm</dc:creator>
      <guid isPermaLink="false">26127@/two/discussions</guid>
      <description><![CDATA[<p>I have a simple push button connected to pin 2 on my arduino. I can read this value and print it to the serial monitor without any trouble:</p>

<p>```
int pushButton = 2;</p>

<pre><code>void setup() {
  Serial.begin(9600);
  pinMode(pushButton, INPUT);
}

void loop() {
  int buttonState = digitalRead(pushButton);
  Serial.println(buttonState);
  delay(1);        // delay in between reads for stability
}
</code></pre>

<p>```</p>

<p>This prints a value of 0 when the button is not pressed, and 1 if it is.</p>

<p>In processing I want to check if the value is zero or one, and perform some conditional logic. But I can't get the equality right:</p>

<p>```
    Serial myPort;
    String resultString;</p>

<pre><code>void setup(){
  size(640,480);
  printArray(Serial.list());
  String portName = Serial.list()[2];
  myPort = new Serial(this,portName,9600);
  myPort.bufferUntil(10);
}

void draw(){
  //
}

void serialEvent(Serial myPort){
  String inputString = myPort.readStringUntil(10); //until newline or ("\n");
  inputString = trim(inputString);
  println(inputString);
  if (inputString == "1"){ //this doesn't work, even though println will render ("1") plus the newline if button is pushed.
    println("on");
  } else {
    println("off");
  }
}
</code></pre>

<p>```</p>

<p>How do I set up this conditional to do one thing if the button is pushed, and another if it is not?</p>

<p>I've tried converting the string to an int using</p>

<p><code>inputInt = Integer.parseInt(inputString);</code></p>

<p>and then performing the check, but it didn't work.</p>
]]></description>
   </item>
   <item>
      <title>Sound gets distorted when runned in processing</title>
      <link>https://forum.processing.org/two/discussion/25905/sound-gets-distorted-when-runned-in-processing</link>
      <pubDate>Wed, 10 Jan 2018 21:02:54 +0000</pubDate>
      <dc:creator>Faffie</dc:creator>
      <guid isPermaLink="false">25905@/two/discussions</guid>
      <description><![CDATA[<p>Hello World, I have written a processing code and have implemented a sound file. When I play it on a common player, a cleat woman voice comes out. If I run my code processing is distorting her voice into a slow man version... I am runnin processing on a MacBook Pro with the latest Java version.</p>

<pre><code>import processing.serial.*;
import processing.sound.*;


int S1_WAITING_FOR_PEOPLE  = 1;
int S2_PEOPLE_ENTERED      = 2;
int S3_LIGHT_FADE_OUT      = 3;
int S4_DARK                = 4;
int S5_MUSIC               = 5;
int S6_LIGHT_FADE_IN       = 6;
// make sure this is the last!!!!
int TERMINATE              = 7;

int mode = S1_WAITING_FOR_PEOPLE;




int no_one_when_distance_greater_then = 160; // cm
int time_before_dim = 5000; // ms

SoundFile file;
boolean is_playing = false;

Serial myPort;  

int dist;

boolean someone_present = false;
int someone_present_since_time;


int music_playing_since;
int music_duration;

int in_mode_since_ms;

void setup() {
  size(640, 360);

  printArray(Serial.list()); // "/dev/cu.usbmodem1411" cu.usb!!!

  myPort = new Serial(this, Serial.list()[1], 9600);
  //myPort.readStringUntil('\n');
  myPort.bufferUntil('\n');

  // Load a soundfile from the data folder of the sketch and play it back in a loop
  file = new SoundFile(this, "03.mp3");
  //file.loop();
  music_duration = (int) file.duration() * 1000;
  music_duration += 2000;

}      

void draw() {
  background(0);
  fill(255);
  text("frameCount: "+frameCount, 50, 25);
  text("dist: "+dist, 50, 50);
  text("mode: "+mode, 50, 75);


  if (frameCount == 180) {
    turn_on();
  } else if (frameCount &gt; 180) {

    if ( mode == S1_WAITING_FOR_PEOPLE) {

      if (someone_present == false) {
        if (dist &lt; no_one_when_distance_greater_then) {
          someone_present = true;
          someone_present_since_time = millis();
          change_mode(mode + 1);
        }
      }
    } else if (mode == S2_PEOPLE_ENTERED) {
      text("millis: "+millis(), 50, 100);
      text("someone_present_since_time: "+someone_present_since_time, 50, 125);
      text("time_before_dim: "+time_before_dim, 50, 150);
      if (millis() - someone_present_since_time &gt; time_before_dim) {
        change_mode(mode + 1);
      }
    } else if (mode == S3_LIGHT_FADE_OUT) {
      turn_off();
      change_mode(mode + 1);
    } else if (mode == S4_DARK) 
    {
      change_mode(mode + 1);
    } else if (mode == S5_MUSIC) 
    {
      if (is_playing == false) {
        file.play();
        is_playing = true;
        music_playing_since = millis();
      }
      if (millis() - music_playing_since &gt; music_duration) {
        is_playing = false;
        file.stop();
        change_mode(mode + 1);
      }
    } else if (mode == S6_LIGHT_FADE_IN) 
    {
      // todo
      if (millis() - in_mode_since_ms &gt; 1000) {
        change_mode(mode + 1);
      }

    } else if (mode == TERMINATE) 
    {
      change_mode(S1_WAITING_FOR_PEOPLE);
      someone_present = false; // reset
      println("turn_on();");
      turn_on();
    }
  }
}


void change_mode(int m) {
  mode = m;
  in_mode_since_ms = millis();
}



void serialEvent(Serial p) { 
  String s = p.readString();
  if (s != null) {
    s = s.replace("\r\n", "");
    if (s.contains("Distance Measured")) {
      String[] tokens = split(s, "=");
      dist = int(tokens[1]);
    }
  }
} 


void turn_on() {
  myPort.write("on");
}

void turn_off() {
  myPort.write("off");
}

void keyPressed() {
  if (key == 'a') {
    turn_on();
  }
  if (key == 's') {
    turn_off();
  }
}
</code></pre>

<p>Thanks for your help!</p>
]]></description>
   </item>
   <item>
      <title>communicate between two macs in processing</title>
      <link>https://forum.processing.org/two/discussion/25841/communicate-between-two-macs-in-processing</link>
      <pubDate>Fri, 05 Jan 2018 20:53:36 +0000</pubDate>
      <dc:creator>Faffie</dc:creator>
      <guid isPermaLink="false">25841@/two/discussions</guid>
      <description><![CDATA[<p>Hello world,
I would like to know if it is possible to communicate between two macs in processing. What I mean:</p>

<p><em>Mac1 sends a signal to mac2 -&gt; mac2 plays an audio file -&gt; mac 2 waits for another signal sent by mac1 (loop)</em></p>

<p>In the code I have written I would love to send a signal to the second mac (mac2) at "int S5_MUSIC = 5;". So that there will be two sounds played at the same time. I need the second mac for a second pair of boxes, to create a surround sound....</p>

<p><strong>This is my processing code:</strong></p>

<pre><code>import processing.serial.*;
import processing.sound.*;


int S1_WAITING_FOR_PEOPLE  = 1;
int S2_PEOPLE_ENTERED      = 2;
int S3_LIGHT_FADE_OUT      = 3;
int S4_DARK                = 4;
int S5_MUSIC               = 5;
int S6_LIGHT_FADE_IN       = 6;
// make sure this is the last!!!!
int TERMINATE              = 7;

int mode = S1_WAITING_FOR_PEOPLE;




int no_one_when_distance_greater_then = 160; // cm
int time_before_dim = 5000; // ms

SoundFile file;
boolean is_playing = false;

Serial myPort;  

int dist;

boolean someone_present = false;
int someone_present_since_time;


int music_playing_since;
int music_duration;

int in_mode_since_ms;

void setup() {
  size(640, 360);

  printArray(Serial.list()); // "/dev/cu.usbmodem1411" cu.usb!!!

  myPort = new Serial(this, Serial.list()[1], 9600);
  //myPort.readStringUntil('\n');
  myPort.bufferUntil('\n');

  // Load a soundfile from the data folder of the sketch and play it back in a loop
  file = new SoundFile(this, "Ex.wav");
  //file.loop();
  music_duration = (int) file.duration() * 1000;
  music_duration += 2000;

}      

void draw() {
  background(0);
  fill(255);
  text("frameCount: "+frameCount, 50, 25);
  text("dist: "+dist, 50, 50);
  text("mode: "+mode, 50, 75);


  if (frameCount == 180) {
    turn_on();
  } else if (frameCount &gt; 180) {

    if ( mode == S1_WAITING_FOR_PEOPLE) {

      if (someone_present == false) {
        if (dist &lt; no_one_when_distance_greater_then) {
          someone_present = true;
          someone_present_since_time = millis();
          change_mode(mode + 1);
        }
      }
    } else if (mode == S2_PEOPLE_ENTERED) {
      text("millis: "+millis(), 50, 100);
      text("someone_present_since_time: "+someone_present_since_time, 50, 125);
      text("time_before_dim: "+time_before_dim, 50, 150);
      if (millis() - someone_present_since_time &gt; time_before_dim) {
        change_mode(mode + 1);
      }
    } else if (mode == S3_LIGHT_FADE_OUT) {
      turn_off();
      change_mode(mode + 1);
    } else if (mode == S4_DARK) 
    {
      change_mode(mode + 1);
    } else if (mode == S5_MUSIC) 
    {
      if (is_playing == false) {
        file.play();
        is_playing = true;
        music_playing_since = millis();
      }
      if (millis() - music_playing_since &gt; music_duration) {
        is_playing = false;
        file.stop();
        change_mode(mode + 1);
      }
    } else if (mode == S6_LIGHT_FADE_IN) 
    {
      // todo
      if (millis() - in_mode_since_ms &gt; 1000) {
        change_mode(mode + 1);
      }

    } else if (mode == TERMINATE) 
    {
      change_mode(S1_WAITING_FOR_PEOPLE);
      someone_present = false; // reset
      println("turn_on();");
      turn_on();
    }
  }
}


void change_mode(int m) {
  mode = m;
  in_mode_since_ms = millis();
}



void serialEvent(Serial p) { 
  String s = p.readString();
  if (s != null) {
    s = s.replace("\r\n", "");
    if (s.contains("Distance Measured")) {
      String[] tokens = split(s, "=");
      dist = int(tokens[1]);
    }
  }
} 


void turn_on() {
  myPort.write("on");
}

void turn_off() {
  myPort.write("off");
}

void keyPressed() {
  if (key == 'a') {
    turn_on();
  }
  if (key == 's') {
    turn_off();
  }
}
</code></pre>

<p>Thanks for your effort.
Faffie</p>
]]></description>
   </item>
   <item>
      <title>Unknown issue with drawing graph with data send by arduino to Raspberry Pi</title>
      <link>https://forum.processing.org/two/discussion/24749/unknown-issue-with-drawing-graph-with-data-send-by-arduino-to-raspberry-pi</link>
      <pubDate>Thu, 26 Oct 2017 11:51:12 +0000</pubDate>
      <dc:creator>maxim221</dc:creator>
      <guid isPermaLink="false">24749@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>I'm using arduino as ADC, which sends data through UART to Raspberry Pi model B, which draws a graph on 7'display, connected via HDMI.</p>

<p>So I've got a strange problem. 
<img src="https://forum.processing.org/two/uploads/imageupload/419/7UPQJMK8SSJH.PNG" alt="pic1" title="pic1" />
Randomly straight lines appear from current measuring point to top of the screen.</p>

<p>I was thinking about mistakes or zero values or Nan values of something like that. But it is not-)</p>

<p>Lines drawn like that:</p>

<p><code>line(xPos-1, height-lastfValue, xPos, height - fValue);</code></p>

<p>I was trying to filter it out by using such a construction:</p>

<pre><code>if(fValue &lt;= 0 || (height - fValue) &gt; height || ((fValue - lastfValue)*(fValue - lastfValue)/2) &gt; lastfValue + 5 ){
    fValue = lastfValue;
    }
</code></pre>

<p>It helped a little, but did't became a solution for my problem. So I tried to figure out a problem and added pdf export of what I see on the screen and logging values of "fValue" to console and find out:</p>

<p>The values:</p>

<pre><code>145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
146.04106
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
</code></pre>

<p>and the graph:</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/787/SFMDC2MDA7NK.jpg" alt="-DLm7tClrdw" title="-DLm7tClrdw" /></p>

<p>As you can see there only one different value and two peaks on the graph.</p>

<p>Does anyone know how to deal with it and get a correct graph?</p>

<p>This code works the same way on my notebook..</p>

<p>Here is the code I use for processing on raspberry Pi:</p>

<pre><code>import processing.serial.*;
import processing.pdf.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph

float fValue;
float lastfValue;
boolean newVal = false;

void setup () {
  size(1000, 300);
 // fullScreen();

  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 115200);
  myPort.bufferUntil('\n');
  background(28,28,28);
  beginRecord(PDF, "rawData.pdf");
}

void draw () {
//  if (newVal) {
    stroke(255, 16, 0);
   // size(100, 100, P3D);
   // noSmooth();
    //ellipse(xPos, height - fValue, 1, 1);
    line(xPos-1, height-lastfValue, xPos, height - fValue);
    println(fValue);
    lastfValue = fValue;
    //fValue = (fValue - 3);
    //stroke(28, 28, 28);
    //point(xPos, height - fValue);
    if (++xPos &gt;= width) {
      xPos = 0;
      background(28,28,28);
//    }
//    newVal = false;
  }
}

void serialEvent (Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    inString = trim(inString);
    fValue = float(inString);
    fValue = map(fValue, 0, 1023, 0, height);
    //if(fValue &lt;= 0 || (height - fValue) &gt; height || ((fValue - lastfValue)*(fValue - lastfValue)/2) &gt; lastfValue + 5 ){
    //fValue = lastfValue;
    //}
  }
//  newVal = true;
}
  void keyPressed() {
  if (key == ' ') {
    endRecord();
    exit();
  }
}
</code></pre>

<p>Here is the code for arduino Uno that I use as ADC:</p>

<pre><code>// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>android serial usb arduino hiccups?</title>
      <link>https://forum.processing.org/two/discussion/24989/android-serial-usb-arduino-hiccups</link>
      <pubDate>Mon, 13 Nov 2017 16:54:07 +0000</pubDate>
      <dc:creator>vagos21</dc:creator>
      <guid isPermaLink="false">24989@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone, i've been working with processing and the android mode for a few days now, and i decided to do this little sensors report when i plug in my android phone to my arduino. i set up the manifest with the vendor IDs and everything and it all works fine but...</p>

<p>even though the arduino Tx lights up continuously (sends data all the time) the processing software looks like it's getting data for a couple of seconds, then looks completely idle for 10 seconds, then takes data again, then no comminucation again... i know the app is not freezing because i'm doing a sliding graph, which happily slides along. any idea what could be causing this hiccup? a buffer overrun?</p>

<p>to be honest i'm trying to make something like a semi-fast DMM, and right now the arduino sends 2 values every 100ms, <a href="/two/profile/38400">@38400</a> baud. is this too fast for the app to handle?</p>

<p>forgive me for the following, but i can't find a code format button...? :D</p>

<p>this is the arduino code:</p>

<pre><code> void setup() {
   Serial.begin(38400);
   pinMode(A0,INPUT);
   pinMode(A1,INPUT);
}

void loop() {
  Serial.print(analogRead(A0));
  Serial.print(";");
  Serial.println(analogRead(A1));
  delay(150);
}
</code></pre>

<p>and the android side:</p>

<pre><code>import io.inventit.processing.android.serial.*; //ANDROID

//SERIAL PORT
Serial myPort;      //thermostat serial port
String inString=""; //input string from serial port

//FONTS
PFont dateFont;           //date font

//REALTIME DATA
float v1 = 0.0;  //voltage1
float v2 = 0.0;  //voltage2

//COLORS
color activeText = color(182, 230, 244);
color inactiveText = color(60, 60, 60);

//BUTTONS
transButton resetBtn = new transButton( width/2, height-50, 200, 50, "Reset");


void setup() {
  fullScreen();
  orientation(LANDSCAPE);
  frameRate(200);

  //init fonts
  dateFont = createFont("WalkwayBold.ttf", 60);

  //init USB serial port
  myPort = new Serial(this, Serial.list(this)[0], 38400); //ANDROID
  myPort.bufferUntil(10);
}

//===========INCOMING DATA FROM THERMOSTAT=============
void serialEvent(Serial myPort) { 
  try {
    inString = myPort.readString();
    String[] list = split(inString, ';');
    v1 = float(list[0])/1024.0;
    v2 = float(list[1])/1024.0;
  }
  catch(RuntimeException e) {
    e.printStackTrace();
  }
}

//===============MAIN LOOP===================
void draw() {
  //timeNow = millis();
  drawMainScreen();
}


//===============DRAWING LOOP===================
void drawMainScreen() {
  background(36,93,142);

  //voltage 1
  fill(255);
  textFont(dateFont);
  textAlign(LEFT, CENTER);
  text("v1: " + v1 + "V", 50, 20);

  //voltage 2
  fill(255);
  textFont(dateFont);
  textAlign(LEFT, CENTER);
  text("v2: " + v2 + "V", 50, 80);

  //raw serial input
  fill(255);
  textFont(dateFont);
  textAlign(CENTER, TOP);
  text("raw: " + inString, 700, 20);
</code></pre>
]]></description>
   </item>
   <item>
      <title>Play video using Processing, Arduino and PIR Sensor</title>
      <link>https://forum.processing.org/two/discussion/25365/play-video-using-processing-arduino-and-pir-sensor</link>
      <pubDate>Sun, 03 Dec 2017 22:41:30 +0000</pubDate>
      <dc:creator>m4rdones</dc:creator>
      <guid isPermaLink="false">25365@/two/discussions</guid>
      <description><![CDATA[<p>Hi. A friend and I are in the middle of a video installation tests. I'm using an Arduino PIR Sensor and an Arduino Uno board.</p>

<p>I need to stop a video when the PIR is "On" (Detects motion) and to play that video if the PIR is "Off".</p>

<p>Checking the Processing and Arduino websites, examples and references I couldn't figured out what I'm doing wrong.
Please let me know if something is missing or left.
Thanks in advance for any help!</p>

<p>This is the Arduino Code (copied from Arduino and Processing communication tutorials found on the web):</p>

<pre><code>/*
   PIR sensor tester
*/

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

  Serial.begin(9600);
}

void loop() {
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH) {
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}
</code></pre>

<p>And here is the Processing code:</p>

<pre><code>import processing.serial.*;
import processing.video.*; 

Serial myPort;
String val;    

Movie video;

void setup() {
  size(640,480);
  video = new Movie(this,"sujeto1.mp4");
  video.loop();
  String portName = Serial.list()[0];
  myPort = new  Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
}

void serialEvent (Serial myPort) {
  if (myPort.available() &gt; 0) {
    val=myPort.readStringUntil('\n');
  }
  if (val=="Motion detected!") {
    video.stop();
  } else {
    video.loop();
  }
  println(val);

}
void draw() {
  background(0);
  image(video,0,0);

} 

void movieEvent(Movie video) {
  video.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Serial not working</title>
      <link>https://forum.processing.org/two/discussion/24898/serial-not-working</link>
      <pubDate>Tue, 07 Nov 2017 16:47:11 +0000</pubDate>
      <dc:creator>plux</dc:creator>
      <guid isPermaLink="false">24898@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I've been writing this code since yesterday and it was fine until now. I don't know what happened but the SerialEvent() is never triggered. Context:
win10 x64, using a bluetooth HC-06 module with arduino. Tested with Bluetooth serial terminal application and all working. In processing, the COM port selected is correct (doesn't throw any error) but the SerialEvent() is <strong>never</strong> triggered therefore no values are received by processing. This was working perfectly an hour ago and I have no idea why it does not work anymore. Basically the BT module is always blinking (which means it's not connected). It used to stop blinking when I run the application (and data was received)</p>

<p>This is extract of my code. None of the print statement inside serialEvent() are actually ever exectued. Again, I receive the values correctly if I run the <a rel="nofollow" href="https://www.microsoft.com/en-us/store/p/bluetooth-serial-terminal/9wzdncrdfst8">Bluetooth Serial Terminal application</a></p>

<pre><code>void setup(){
    size(800, 800, P3D);
    //fullScreen(P3D, 1);

    // OSC stuff
    oscP5 = new OscP5(this, 10000);
    destination = new NetAddress("127.0.0.1", oscPort);

    //Serial stuff
    String portName = Serial.list()[1];
    my_port = new Serial(this, portName, 9600);
    my_port.bufferUntil('\n');

    background(0);
}

void serialEvent(Serial my_port){
  println("MESS");
  if(my_port != null){
    String str = my_port.readStringUntil('\n');

    if(str.charAt(0) == '#'){
      str = trim(str.substring(1));

      int gyro[] = int(split(str,','));

      for(int i = 0; i &lt; gyro.length;i++){
          gyroVals[i] = (int) map(gyro[i], 0, 360, -180, 180);
          print(i + ": " + gyroVals[i] + " // "); 
      }  
        println();
    }
  } 
} //serialEvent
</code></pre>
]]></description>
   </item>
   <item>
      <title>Port get busy after a few times running. Is it because of P3D?</title>
      <link>https://forum.processing.org/two/discussion/24569/port-get-busy-after-a-few-times-running-is-it-because-of-p3d</link>
      <pubDate>Sun, 15 Oct 2017 23:56:57 +0000</pubDate>
      <dc:creator>TuangPing</dc:creator>
      <guid isPermaLink="false">24569@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have come to a problem of having error from using Window 7 with arduino Leonado sending data through Serial port.
I tested a code that getting only the data from both Mac and Window and it works fine. Then I make a video to put on a canvas for Spout to project it out to other program. Note that with syphon everything works fine too. I have ran into a post somewhere that posted long ago that a guy had the same problem of mine and he fixed it by changing to openGL but I also learned that openGL now is the same as P3D from a more recent post here in this forum. ** I didn't run anything at the same time of processing.** First time running usually fine, but for the second or third then the error will say that my port is busy! And I will have no choice but  restart the computer again. !!!! Is this a bug? Is there a solution?</p>

<p>Here is the code that runs fine on both operation</p>

<pre><code>import processing.serial.*;
Serial myPort ;
int value, wheel;
String myString = null;
int weight = 800;
int lf = 10;

void setup() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[1], 9600);
  myPort.clear();
  myPort.bufferUntil(lf);
  myString = myPort.readStringUntil(lf);
}
void draw() {
println("in draw once");
 println("fsr: "+ value);
    println("wheel position: "+ wheel);
    println("-----------");
}

void serialEvent(Serial p) {
  //println("access Serial port");
  myString = p.readStringUntil('\n');
  if (myString !=null) {
    //println("get data from Serial port");
    String[] fsr =split(myString, 'r');
    //printArray(fsr);
    value = int(fsr[0]);
    String trim = trim(fsr[1]);
    wheel = int(trim);

  }
}
</code></pre>

<p>And this is a code that has a problem in Window 7 (x64)</p>

<pre><code>import spout.*;// IMPORT THE SPOUT LIBRARY
import processing.serial.*;//Serial to Arduino
import processing.video.*;//play vdo

int nSenders = 5;
PGraphics[] canvas;
Spout[] senders;

int lf=10;
Serial myPort;
int value, wheel;
String myString = null;
Movie myMovie;
int arduinoValue = 800;

int projectorWidth = 1024;
int projectorHeight = 768;
//int scalar = 3;

//-----swtiches------//
Boolean arduinoSwitch = true;
Boolean sensorSwitch = false;
Boolean spoutSwitch = true;
//-----------//

void settings() {
  size(projectorWidth, projectorHeight,P3D);
  // size is doesn't change the size of canvas in term of sending graphic signal out.
}
void setup() {
  canvas = new PGraphics[nSenders];
  for (int i=0; i&lt;nSenders; i++) {
    canvas[i] = createGraphics(projectorWidth, projectorHeight, P3D);
  }
  printArray(Serial.list());

  // Create Spout senders to send frames out.
  if (spoutSwitch) {
    senders = new Spout[nSenders];
    for (int i = 0; i &lt; nSenders; i++) { 
      senders[i] = new Spout(this);
      String sendername = "Test "+i;
      senders[i].createSender(sendername, projectorWidth, projectorHeight);
    }
  }  
  if (arduinoSwitch) {
    myPort = new Serial(this, Serial.list()[1], 9600);
    myPort.clear();
    myPort.bufferUntil(lf);
    myString = myPort.readStringUntil(lf);
  }
  myMovie = new Movie (this, "C:/Users/dma/Desktop/tuang/test1.mp4");
}

void draw() {
  canvas[0].beginDraw();
  canvas[0].background(255, 0, 100);
  canvas[0].image(myMovie, 0, 0);
  if (spoutSwitch) {
    for (int i = 0; i &lt; nSenders; i++) {
      senders[i].sendTexture(canvas[i]);    //send all separated spout canvases
    }
  }
  if (arduinoSwitch) {
    println("fsr: "+value);
    println("position wheel: "+wheel);
    if (value &lt; arduinoValue) {
      sensorSwitch=true;
      myMovie.stop();
      canvas[0].background(0);
      println("nothing in the house");
    }
    if (sensorSwitch) {
      if (value&gt;=arduinoValue) {
        println("Force sensor is detacted");
        //newRandom=true;
        //randomMovie();
        myMovie.play();
        sensorSwitch=false;
      }
    }
  }
  canvas[0].endDraw();
  image(canvas[0], 1024/2*(0%2), 768/2*(0/2));
}
void movieEvent(Movie m) {
  m.read();
}

void serialEvent(Serial p) {
  if (arduinoSwitch) {
    myString = p.readStringUntil('\n');
    if (myString != null) {
      String[] fsr = split(myString, 'r');
      //printArray(fsr);
      value = int(fsr[0]);
      String trim = trim(fsr[1]);
      wheel = int(trim);
    }
  } else {
    println("Arduino is off.");
  }
}
//keyboard for testing vdo
void keyPressed() {
  switch (key) {
  case 'a' : 
    myMovie.play();
    break;
  case 'r' :
    myMovie.stop();
    break;
  }
}
</code></pre>

<p>What should I do to stop the port being too busy ! I didn't even run anything but processing.</p>
]]></description>
   </item>
   <item>
      <title>How do I receive multiple values through Processing from the Arduino Serial Monitor</title>
      <link>https://forum.processing.org/two/discussion/24307/how-do-i-receive-multiple-values-through-processing-from-the-arduino-serial-monitor</link>
      <pubDate>Fri, 29 Sep 2017 09:13:36 +0000</pubDate>
      <dc:creator>ash8</dc:creator>
      <guid isPermaLink="false">24307@/two/discussions</guid>
      <description><![CDATA[<p>Hi experts, newbie here,</p>

<p>I am having trouble reading data from the serial monitor sent by my Arduino in processing.
Im not sure how to read multiple values.</p>

<p>Here is my Arduino data being sent to the serial monitor (9600 baud):</p>

<p><code>Serial.print(LeftSensor);
Serial.print(',');
Serial.print(FrontSensor);
Serial.print(',');
Serial.print(RightSensor);</code></p>

<p>Here is my processing serial reading function:</p>

<pre><code>import processing.serial.*;
Serial port;
float center = 0;
float left = 0;
float right = 0;


void setup(){
size(480, 300); // AqT arduino quad test
port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
port.bufferUntil('\n');
}

void serialEvent()
{ 
  int newLine = 13; // new line character in ASCII
  String message;
  do {
    message = port.readStringUntil(newLine); // read from port until new line
    if (message != null) {
      String[] list = split(trim(message), " ");
      if (list.length &gt;= 4 &amp;&amp; list[0].equals("Stuff: ")) {
        //yaw = float(list[1]); // convert to float yaw
        //pitch = float(list[2]); // convert to float pitch
        left = float(list[1]);
        center = float(list[2]);
        right = float(list[3]);
        roll = float(list[4]);
      }
      else{
      rect(20, 20, 20, 20);
      }
    }
  } while (message != null);
}

void draw(){
  serialEvent();  
}
</code></pre>

<p>When I try the code out, Processing reads nothing but the arduino works fine in terms of output.</p>

<p>Please help,</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Why can't I get the option pane to show.</title>
      <link>https://forum.processing.org/two/discussion/24430/why-can-t-i-get-the-option-pane-to-show</link>
      <pubDate>Sat, 07 Oct 2017 12:29:01 +0000</pubDate>
      <dc:creator>stumped1</dc:creator>
      <guid isPermaLink="false">24430@/two/discussions</guid>
      <description><![CDATA[<p>A newby and my first time using Processing and I can't see how I can resolve this. I'm trying to set up a CNC drawing setup in arduino uno and the Processing option pane is not displaying correctly. I've attached a screenshot and it appears a fault is shown at line 31. 
Would greatly appreciate any help<img src="https://forum.processing.org/two/uploads/imageupload/412/C67EN4DZYET8.png" alt="Screenshot (5)" title="Screenshot (5)" /></p>
]]></description>
   </item>
   <item>
      <title>loosing or gaining bytes through serial</title>
      <link>https://forum.processing.org/two/discussion/24268/loosing-or-gaining-bytes-through-serial</link>
      <pubDate>Tue, 26 Sep 2017 15:21:54 +0000</pubDate>
      <dc:creator>w4lt3r</dc:creator>
      <guid isPermaLink="false">24268@/two/discussions</guid>
      <description><![CDATA[<p>hello</p>

<p>I have a issue that Processing isn't reading out all(or too much) of the data it gets.</p>

<p>I am sending data from the arduino(in this case just the numbers 1-6) and want to read them out in processing. the Baudrate has some  effect but above and below 9600 it gets worse. I had in the past a delay in the arduino code, it didn't worked out neither.
 the catch(nullPointerException e) is there to catch strings that are 0, happened too in the past.</p>

<p>if i use other tools to read out the data from the serial such as the arduino serial monitor or Tera Term then there are no missing character/bytes.</p>

<p>SerialEvent doesn't trigger at all(with bufferuntil(10) or ('\n').</p>

<p>I hope someone has some ideas where the bug is crawling around.</p>

<p>walter</p>

<p>the processing code;</p>

<p>```
    import processing.serial.*;</p>

<pre><code>Serial myPort;        // The serial port
int xPos = 1;
int i,j,h,ii;         // horizontal position of the graph 
int lastxPos=1;
int lastheight=0;
int xPos1 = 1;         // horizontal position of the graph 
int lastxPos1=1;
int lastheight1=0;

String a="0";
int n=5;
String[] indata={a,a,a,a,a,a,a};//new String[6];
String[] indata2=new String[7];
  String InString;
int[] rawdata=new int[7];
float[] data=new float[7];
PrintWriter output;
//Variables to draw a continuous line.


int lf= 10;



public static final int portIndex=1;

void setup () {
  output= createWriter("output");
  // List all the available serial ports
  println(Serial.list());
  // Check the listed serial ports in your machine
  // and use the correct index number in Serial.list()[].
  println(" Connecting to -&gt; " + Serial.list()[portIndex]);
  myPort = new Serial(this, Serial.list()[portIndex], 9600);  //
  delay(3000);
  myPort.write(65);
  // A serialEvent() is generated when a newline character is received :
  myPort.bufferUntil('\n');
  background(7000);      // set inital background:
//  delay(100);
}

void draw(){

//print(InString);
  InString=myPort.readStringUntil('\n');
  print(InString);

  try{
     indata2=split(trim(InString)," ");
  for(int ii=0;ii&lt;indata2.length;ii++){  _**here the error is created**_
    indata[ii]=indata2[ii];
  }}
    catch(NullPointerException e){println("error invalid array");}
  for(int j=0;j&lt;indata.length;j++){
  rawdata[j]=int(trim(indata[j]));
  }
 //  println(rawdata);
 //  println(interval);
}
</code></pre>

<p>the arduino code:</p>

<pre><code>void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i=0;i&lt;7;i++){
Serial.print(i);
Serial.print("\r"" ");
  }
  Serial.print('\n');
}
</code></pre>

<p>and a typical output</p>

<p>5 61 2 3 4 5 6</p>

<p>0 1 2 3 4 5 6</p>

<p>0 0 1 2 3 4 5 6
or
0 1 2 3 4 5 6 1 2 3 4 5 6</p>
]]></description>
   </item>
   <item>
      <title>when i play nine mp4s using video library,the nineth mp4 can't play as other eight mp4.</title>
      <link>https://forum.processing.org/two/discussion/24050/when-i-play-nine-mp4s-using-video-library-the-nineth-mp4-can-t-play-as-other-eight-mp4</link>
      <pubDate>Thu, 07 Sep 2017 05:23:47 +0000</pubDate>
      <dc:creator>Ryan</dc:creator>
      <guid isPermaLink="false">24050@/two/discussions</guid>
      <description><![CDATA[<pre><code>import processing.video.*;  
import processing.serial.*; 
Serial myPort;
int[] valr={1021,1021,1021,1021,1021,1021,1021,1021,1021};
Movie[] endmovie = new Movie[9];
void setup(){  
  fullScreen();
  for(int i = 0;i&lt;9;i++){
endmovie[i] = new Movie(this,"b"+i+".mp4");
  }
  myPort = new Serial(this,Serial.list()[0], 9600);
  myPort.bufferUntil('\n');  //buffer until meet '\n', then call the event listener

}  

void draw(){
  image(endmovie[0],0,0,width/3,height/3);
  image(endmovie[1],width/3,0,width/3,height/3);
  image(endmovie[2],width*2/3,0,width/3,height/3);
  image(endmovie[3],0,height/3,width/3,height/3);
  image(endmovie[4],width/3,height/3,width/3,height/3);
  image(endmovie[5],width*2/3,height/3,width/3,height/3);
  image(endmovie[6],0,height*2/3,width/3,height/3);
  image(endmovie[7],width/3,height*2/3,width/3,height/3);
  image(endmovie[8],width*2/3,height*2/3,width/3,height/3);
for(int i = 0;i&lt;9;i++){
  endmovie[i].play();
   if(valr[i]&gt;500){
endmovie[i].speed(1.0);
   }else{
endmovie[i].speed(-1.0);
   }
 }
}

void movieEvent(Movie m){
  m.read();
}  

void serialEvent(Serial p) {  
  String inString = p.readString();  
  print(inString);
  if(inString!=null){
   String[] rec= split(inString, ',');
   for(int i=0;i&lt;9;i++){
 valr[i]=int(rec[i]);
   }  
  }  
}  
</code></pre>
]]></description>
   </item>
   <item>
      <title>Serial parsing from eeg string</title>
      <link>https://forum.processing.org/two/discussion/23983/serial-parsing-from-eeg-string</link>
      <pubDate>Thu, 31 Aug 2017 16:01:57 +0000</pubDate>
      <dc:creator>iiyeo</dc:creator>
      <guid isPermaLink="false">23983@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I am doing a brainwave eeg project now and I have already got the raw brainwave values in Arduino. It is a string of 11 values. But when I want to parse the eeg string in processing, I got the error 'disabling serialEvent() for /dev/cu.usbmodem1411 null'. I am quite new to processing and I totally have no idea about that. Is there anyone could help me to see this code? Thanks in advance. Sorry for my English if there is any mistake.</p>

<p>PS: I even didn't get the 11 varying values in the below monitor. I can only get data like this:
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0</p>

<p>Here is the code:</p>

<pre><code>import processing.serial.*;
Serial serial;

int signal_strength;
int attention; 
int meditation; 
int delta;
int theta;
int low_alpha;
int high_alpha; 
int low_beta;
int high_beta;
int low_gamma; 
int high_gamma;  


void setup() {


  println("Find your Arduino in the list below, note its [index]:\n");

  for (int i = 0; i &lt; Serial.list().length; i++) {
    println("[" + i + "] " + Serial.list()[i]);
  }

  serial = new Serial(this, Serial.list()[3], 9600);
  serial.bufferUntil(10);

}

void draw() {

  println(signal_strength, attention, meditation, delta, theta, low_alpha, high_alpha, low_beta, high_beta, low_gamma, high_gamma);

}

void serialEvent(Serial serial) {

  String incomingString = serial.readString().trim();

  int[] incomingValues = int(split(incomingString, ","));
    signal_strength = incomingValues[0];
    attention = incomingValues[1];
    meditation = incomingValues[2];
    delta = incomingValues[3];
    theta = incomingValues[4];
    low_alpha = incomingValues[5];
    high_alpha = incomingValues[6];
    low_beta = incomingValues[7];
    high_beta = incomingValues[8];
    low_gamma = incomingValues[9];
    high_gamma = incomingValues[10];

  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Serial library with Processing.py</title>
      <link>https://forum.processing.org/two/discussion/9598/serial-library-with-processing-py</link>
      <pubDate>Fri, 27 Feb 2015 00:27:53 +0000</pubDate>
      <dc:creator>ericksonla</dc:creator>
      <guid isPermaLink="false">9598@/two/discussions</guid>
      <description><![CDATA[<p>Generally, is there library documentation for the libraries with Processing.py?</p>

<p>Specifically, I'm trying to use the Serial library. Guessing the syntax from the Java documentation, I have:</p>

<pre lang="python">
add_library('serial')

def setup():
    #setup the serial port
    print Serial.list()
    portIndex = 4
    LF = 10
    print "Connecting to ", Serial.list()[portIndex]
    myPort = Serial(Serial.list()[portIndex], 9600)   # this seems to need a first argument referring to the sketch object (analagous to "this" argument in Java)
    myPort.bufferUntil(LF)
    
def draw():
    pass
    
def serialEvent(evt):
    inString = evt.readString()
    print inString
</pre>

<p>Anyone have any advice on making this work?</p>

<p>As a side note, it would be nice to add a processing.py as a subcategory in the forums under "Questions and Modes".</p>
]]></description>
   </item>
   <item>
      <title>Working on a code to take input from an Arduino and display the data using Processing.</title>
      <link>https://forum.processing.org/two/discussion/23295/working-on-a-code-to-take-input-from-an-arduino-and-display-the-data-using-processing</link>
      <pubDate>Mon, 03 Jul 2017 11:08:57 +0000</pubDate>
      <dc:creator>bsmyname</dc:creator>
      <guid isPermaLink="false">23295@/two/discussions</guid>
      <description><![CDATA[<p>I have a code written in Arduino that turns the led off and on using if statements.  It displays in the serial monitor the status of the LED and its "input".  It displays 'LED is ON.' 'LED is OFF.' or 'Invalid' depending on what would be the input from the user.  Currently it's automated so I can leave it alone and it scrolls through on off and then invalid every two seconds so I can work on the Processing code.  In Processing, I can bring in the data and display each result once but the code either gets stuck at the end of the loop and draw doesn't seem to run again or there is something wrong with my serial event and my string input from the Arduino doesn't update.  I have attached the Processing code if that will help in understanding what I am trying to do.</p>

<pre><code>   import processing.serial.*;
Serial port;

String serialMonitor = "LED is ON!";       //Determining empty string allows loop to run the first time
String txt = "Unknown!";
String data;
String ledOn = "LED is ON!";
String ledOff = "LED is OFF!";
String invld = "Invalid!";
PFont font;              //Activates font


void setup() {
  size(400, 400);                                          //Determines window size
  port = new Serial(this, "COM4", 9600);                   //
  port.bufferUntil('!');                                   //
  font = loadFont("AmerTypewriterITCbyBT-Medium-48.vlw");     //
  textFont(font, 48);                                     //
  frameRate(60);
}

void draw() {
  background(0);

 if (serialMonitor.equals(ledOn) == true) {
     rectMode(CENTER);
  text(serialMonitor, 200, 200, 300, 50);
  fill(234, 255, 45);                                   //When LED is on
 }

if (serialMonitor.equals(ledOff) == true) {
     rectMode(CENTER);
  text(serialMonitor,200, 200, 300, 50);
  fill(42, 20, 168);                                        //When LED is off  
 }

 if (serialMonitor.equals(invld) == true) {
     rectMode(CENTER);
  text(serialMonitor, 200, 200, 300, 50);
  fill(230, 11, 11);                                  //When input is Invalid
 }

 else {
     rectMode(CENTER);
  text(txt, 200, 200, 300, 50);
  fill(237,233,220);
 }
}

void serialEvent (Serial port) {
serialMonitor = port.readStringUntil('!');        //Reads incoming data string
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to change the stroke of my triangles with serial port data?</title>
      <link>https://forum.processing.org/two/discussion/23218/how-to-change-the-stroke-of-my-triangles-with-serial-port-data</link>
      <pubDate>Mon, 26 Jun 2017 19:02:26 +0000</pubDate>
      <dc:creator>realdapsis</dc:creator>
      <guid isPermaLink="false">23218@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm new to processing and I'm working with this code.. while I accomplished to fade the background I wonder how to change the stroke weight with the same data the background changes. Thanks in advance. This is my code:</p>

<pre><code>import processing.serial.*;
import ddf.minim.*;
import ddf.minim.signals.*;

Minim minim;
AudioPlayer mySound;

Serial port;
float brightness;



void setup() {
size(1000, 500,P3D);


String portName = Serial.list()[2];
port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
port.bufferUntil('\n');
noFill();
strokeWeight(1);

minim = new Minim(this);
mySound = minim.loadFile("bb.mp3");
mySound.play();
mySound.loop();  
}
int n=0;

void draw ()
{
background (brightness, 0, 25);


translate(width/2,height/2);
for(int i = 0; i &lt; mySound.bufferSize() - 1; i++)  {

stroke(random(250),random(250),random(250));

rotateX(n*-PI/6*0.05);
rotateY(n*-PI/6*0.05);
rotateZ(n*-PI/6*0.05);


triangle (i,i,mySound.left.get(i)*50,mySound.left.get(i)*50,i,i);
}
n++;

}

void serialEvent (Serial port)
{
brightness = float (port.readStringUntil ('\n'));



}
</code></pre>
]]></description>
   </item>
   <item>
      <title>error disabling serialEvent ?</title>
      <link>https://forum.processing.org/two/discussion/23123/error-disabling-serialevent</link>
      <pubDate>Sun, 18 Jun 2017 19:18:37 +0000</pubDate>
      <dc:creator>drocobeth</dc:creator>
      <guid isPermaLink="false">23123@/two/discussions</guid>
      <description><![CDATA[<p>i am trying to talk both way round from processing to arduino as well as from arduino to processing. while processing to arduino link is absolutely fine but i guess it shows the error for arduino to processing and it reads somewhat this:
"error disabling serialEvent() for COM3 null". well i have posted my code below please tell me where i am going wrong.the prime idea is to create a GUI for bluetooth controlled bot and to send feeback from arduino to processing regarding the motor encoder to plot the movement graph(closed loop drive).</p>

<pre><code>processing:
        import processing.serial.*;
        Serial port;
             int index=0;
            String lmotor,rmotor,data,status;
            float lm=0,rm=0,xpos=0,ypos=height;
            void settings()
            {
              size(550,600);
            }
            void setup()
            {
               SecondApplet sa= new SecondApplet();
              String[] args = {"MY Sketch"};
              PApplet.runSketch(args, sa);
              port= new Serial(this, "COM3", 9600);
               port.bufferUntil('.');

        }

        void serialEvent (Serial port)
        {
          println(data);
           data=port.readStringUntil('.');
           data=data.substring(0,data.length()-1);
           index=data.indexOf(",");
           lmotor= data.substring(0, index);
           rmotor= data.substring(index+1 , data.length());
           lm=float(lmotor);
           rm=float(rmotor);
           lm=map(lm,0,9999,0,width);
           rm=map(rm,0,9999,0,height);



        }

        void octagon(int x, int y, int radius)
        {
          float angle= TWO_PI/ 8;
          beginShape();
          for(float a=0; a&lt;TWO_PI; a+= angle)
          {
            float sx= x + cos(a) * radius;
            float sy= y + sin(a) * radius;
            vertex(sx,sy);
          }
          endShape(CLOSE);
        }
        void draw() {
          background(245, 255, 245);
          fill(20 , 160, 133);
          stroke(33);
          strokeWeight(3);
          rect(50, 150, 200, 100, 10);
          rect(300, 150, 200, 100, 10);
          fill(255);
          textSize(34);
          text("FORWARD" , 70,205);
          text("BACKWARD", 305, 205);
          textSize(28);
          fill(33);
          text("CURRENT STATUS:", 180, 300);
          //stop button
          fill(176, 28, 46);
          octagon(60,60, 50);
          fill(255);
          rect(30,50,60,17);
          textSize(24);
          fill(33);
          text("STOP", 30,135);
          //left arrow
           ellipseMode(CORNER);
          fill(255,77,0);
          ellipse(35,440,220,120);
          fill(255);
          beginShape();
          {
            vertex(40, 500);
            vertex(100, 450);
            vertex(100, 475 );
            vertex(240,475 );
            vertex(240,525);
            vertex(100, 525);
            vertex(100,550);
          }
          endShape(CLOSE);
           // right arrow
           ellipseMode(CORNER);
           fill(255,77,0);
           ellipse(295,440,220,120);
           fill(255);
           beginShape();
          {
            vertex(510, 500);
            vertex(450, 450);
            vertex(450, 475 );
            vertex(310,475 );
            vertex(310,525);
            vertex(450, 525);
            vertex(450,550);
          }
          endShape(CLOSE);
          if(mousePressed &amp;&amp; mouseX&gt;10 &amp;&amp; mouseX&lt;110 &amp;&amp; mouseY&gt;10 &amp;&amp; mouseY&lt;110)
          {
             port.write('0');
             stroke(255,0,0);
            strokeWeight(2);
            noFill();
            octagon(60,60, 50);
            status="STOP";
          }
          if(mousePressed &amp;&amp; mouseX&gt;50 &amp;&amp; mouseX&lt;250 &amp;&amp; mouseY&gt;150 &amp;&amp; mouseY&lt;250)
          {
            port.write('F');
             stroke(255,0,0);
            strokeWeight(2);
            fill(255);
            rect(50,150,200,100,10);
            status="FORWARD";
            }
           if(mousePressed &amp;&amp; mouseX&gt;300 &amp;&amp; mouseX&lt;500 &amp;&amp; mouseY&gt;150 &amp;&amp; mouseY&lt;250)
          {
             port.write('B');
             stroke(255,0,0);
            strokeWeight(2);
            fill(255);
            rect(300,150,200,100,10);
            status="BACKWARD";
          }
           if(mousePressed &amp;&amp; mouseX&gt;35 &amp;&amp; mouseX&lt;255 &amp;&amp; mouseY&gt;440 &amp;&amp; mouseY&lt;560)
          {
              port.write('L');
             stroke(255,0,0);
            strokeWeight(2); 
           ellipseMode(CORNER);
             fill(255);
          ellipse(35,440,220,120);  
          status="LEFT";
         }
           if(mousePressed &amp;&amp; mouseX&gt;295 &amp;&amp; mouseX&lt;515 &amp;&amp; mouseY&gt;440 &amp;&amp; mouseY&lt;560)
          {
             port.write('R');
             stroke(255,0,0);
            strokeWeight(2); 
           ellipseMode(CORNER);
             fill(255);
         ellipse(295,440,220,120);
         status="RIGHT";
         }
          if(status=="FORWARD")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,140,380);
          }
          if(status=="BACKWARD")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,120,380);
          }
          if(status=="RIGHT")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,200,380);
          }
          if(status=="LEFT")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,230,380);
          }
          if(status=="STOP")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,210,380);
          }



        }
        public class SecondApplet extends PApplet {




          public void settings() {
            size(550, 600);
          }
          public void setup()
          {
            background(0);
          }
          public void draw()
          {
             stroke(255);
          strokeWeight(5);
           line(xpos,ypos,lm,height-rm);
          xpos=lm;
          ypos=height-rm;
          if(lm&gt;=width-1)
          {
            xpos=0;
            lm=0;
            background(0);
          }
          if(rm&gt;=height-1)
          {
            ypos=0;
            rm=0;
            background(0);
          }



      }
    }
</code></pre>

<p>arduino code:
        #include &lt;avr/io.h&gt;
        #include &lt;util/delay.h&gt;</p>

<pre><code>#define SETBIT(ADDRESS, BIT) (ADDRESS|=(1&lt;&lt;BIT));
#define CLEARBIT(ADDRESS, BIT) (ADDRESS&amp;=~(1&lt;&lt;BIT));
#define CHECKBIT(ADDRESS, BIT) (ADDRESS &amp; (1&lt;&lt;BIT));
char val,c;
int sfl=0,sfr=0,temp,y=0;

void interrupt_init()
{
  cli();
  EIMSK=0x03;
  EICRA=0x0A;
  sei();

}
void encoder_pin_config_init()
{
  DDRD=DDRD &amp; 0xF3;
  //INTERNALPULLUPS
  SETBIT(PORTD, PD3);
  SETBIT(PORTD, PD2);
}
void byte_init (int baud)
{
    UBRR0H = (baud&gt;&gt;8);                      // shift the register right by 8 bits
    UBRR0L = baud;                           // set baud rate
    UCSR0B|= (1&lt;&lt;TXEN0)|(1&lt;&lt;RXEN0);                // enable receiver and transmitter
    UCSR0C|= (1&lt;&lt;UCSZ00)|(1&lt;&lt;UCSZ01);   // 8bit data format
}
void byte_transmit (unsigned char data)
{
    while (!( UCSR0A &amp; (1&lt;&lt;UDRE0)));                // wait while register is free
    UDR0 = data;                                   // load data in the register
}
unsigned char byte_receive (void)
{
    while(!(UCSR0A) &amp; (1&lt;&lt;RXC0));                   // wait while data is being received
    return UDR0;                                   // return 8-bit data
}


int main(void)
{
  byte_init(103);
  interrupt_init();
  encoder_pin_config_init();
  DDRB = (1&lt;&lt;PB1) | (1&lt;&lt;PB2); // PWM pins &amp;&amp; Enable pins
DDRD = (1&lt;&lt;PD4) | (1&lt;&lt;PD5) | (1&lt;&lt;PD6) | (1&lt;&lt;PD7) ; //Motor Pins

SETBIT(PORTB, PB1);
SETBIT(PORTB,PB2);
while(1)
{
val=byte_receive();
if(val=='0')
{
  Stop();
}
if(val=='F')
{
  Forward();
}
if(val=='B')
{
  Backward();
}
if(val=='R')
{
  right();
} 
if(val=='L')
{
  left();
}
temp=sfl;
while(temp&gt;0)
{
  y=temp%10;
  c=y+'0';
  byte_transmit(c);
  temp=temp/10;

}
temp=sfr;
while(temp&gt;0)
{
  y=temp%10;
  c=y+'0';
  byte_transmit(c);
  temp=temp/10;
}
byte_transmit('.');
if(sfl==9999)
{
  sfl=0;
}
if(sfr==9999)
{
  sfr=0;
}
}

}
void Stop()
{
  CLEARBIT(PORTD,PD4);
  CLEARBIT(PORTD, PD5);
  CLEARBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD7);
}
void Forward()
{
  SETBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
  SETBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD7);
}
void Backward()
{
  SETBIT(PORTD, PD5);
  CLEARBIT(PORTD, PD4);
  SETBIT(PORTD, PD7);
  CLEARBIT(PORTD, PD6);
}
void left()
{
  CLEARBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
  SETBIT(PORTD, PD7);
  CLEARBIT(PORTD, PD6);
}

    void right()
    {
  SETBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
}

ISR(INT0_vect)
{
  sfl++;
}
ISR(INT1_vect)
{
  sfr++;
}`
</code></pre>
]]></description>
   </item>
   <item>
      <title>Creating an array with movie files, and shuffling it.</title>
      <link>https://forum.processing.org/two/discussion/23023/creating-an-array-with-movie-files-and-shuffling-it</link>
      <pubDate>Sun, 11 Jun 2017 13:05:54 +0000</pubDate>
      <dc:creator>blazebattery</dc:creator>
      <guid isPermaLink="false">23023@/two/discussions</guid>
      <description><![CDATA[<p>Hey everyone,</p>

<p>I'm creating a movie player program with an Arduino board. I've successfully made the program play one movie file when I wave my hand in front of the Arduino PIR monitor, I just want it to randomly select from an array of other video files. Any help would be appreciated.</p>

<p>Here's my code so far...</p>

<pre><code>import processing.video.*;
import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph, original 1
float inByte = 0;

String[] movieNames = { "1.mpg", "2.mpg", "3.mpg", "4.mpg"};
Movie[] movee = new Movie[movieNames.length];

void setup() {
  fullScreen();
  background(0);

  myPort = new Serial (this, "COM6", 9600);
  myPort.bufferUntil('\n');

  for (int i=0; i&lt;movieNames.length; i++) {
    movee[i] = new Movie(this, movieNames[i]);
  }
}

void draw() {

  for (int i = 0; i &lt; movieNames.length; i++) {
    image(movee[0], 0, 0);
  }
}

void movieEvent(Movie m) {
  m.read();
}

void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    inString = trim(inString);
    inByte = float(inString);

    println(inByte);

    if (inByte == 1) {
      movee[0].stop();
      println("Playing video...");
      movee[0].play();
    }

  }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can any one please explain this code line by line as i am new to processing please. (ECG graph)</title>
      <link>https://forum.processing.org/two/discussion/22846/can-any-one-please-explain-this-code-line-by-line-as-i-am-new-to-processing-please-ecg-graph</link>
      <pubDate>Wed, 31 May 2017 19:31:50 +0000</pubDate>
      <dc:creator>utkarsh101</dc:creator>
      <guid isPermaLink="false">22846@/two/discussions</guid>
      <description><![CDATA[<p>This is the code for the ECG graph display using Arduino and AD8232 heart rate sensor.</p>

<pre><code>import processing.serial.*;

Serial myPort;        // The serial port  
int xPos = 1;         // horizontal position of the graph
float height_old = 0;
float height_new = 0;
float inByte = 0;


void setup () {
  // set the window size:
  size(1000, 400);        

  // List all the available serial ports
  println(Serial.list());
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[0], 9600);
  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');
  // set inital background:
  background(0xff);
}


void draw () {
  // everything happens in the serialEvent()
}


void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);

    // If leads off detection is true notify with blue line
    if (inString.equals("!")) { 
      stroke(0, 0, 0xff); //Set stroke to blue ( R, G, B)
      inByte = 512;  // middle of the ADC range (Flat Line)
    }
    // If the data is good let it through
    else {
      stroke(0xff, 0, 0); //Set stroke to red ( R, G, B)
      inByte = float(inString); 
     }

     //Map and draw the line for new data point
     inByte = map(inByte, 0, 1023, 0, height);
     height_new = height - inByte; 
     line(xPos - 1, height_old, xPos, height_new);
     height_old = height_new;

      // at the edge of the screen, go back to the beginning:
      if (xPos &gt;= width) {
        xPos = 0;
        background(0xff);
      } 
      else {
        // increment the horizontal position:
        xPos++;
      }
  }
}
</code></pre>

<p>Any help would be highly appreciated.</p>
]]></description>
   </item>
   <item>
      <title>How do I split an incoming 6 value string into separate variables?</title>
      <link>https://forum.processing.org/two/discussion/22732/how-do-i-split-an-incoming-6-value-string-into-separate-variables</link>
      <pubDate>Tue, 23 May 2017 23:46:41 +0000</pubDate>
      <dc:creator>JsGarage</dc:creator>
      <guid isPermaLink="false">22732@/two/discussions</guid>
      <description><![CDATA[<p>Hey there, This is my first Processing project.
So far it's going well, but I'm stuck with the string splitting bit.</p>

<p>OK, so ive programmed the arduino, and its connected to sensors giving correct values in the serial window (arduinoIDE)</p>

<p>but when Processing grabs the string and splits it, all I'm getting is zeros. Just zeros. nothing but zeros.</p>

<p>the graphic window appears to work correctly given the crappy data its getting.</p>

<p>The program is a live feed connected to an EFI engine for keeping an eye on extra sensors whilst on the Dynamometer.
Anyway, if I could get some help that would be great!</p>

<pre><code>`import grafica.*;
import processing.serial.*;
import processing.serial.Serial;

GPointsArray myArray = new GPointsArray(0);
Serial myPort;                                                   // The serial port
//float inByte = 0;                                              // defines starting value for the serial input(doesnt seem to be needed)
int count;
int[] sensors;                                                   // declare 'sensors' as an array (just incase I need it)
// int value;
int xPos = 20;                                                   // horizontal position of the graph
int yPos = 300;                                                  // current vertical position of the graph
int sensorNum;
int lastxPos = xPos;                                             // previous horizontal position of the graph
int lastyPos0= 0;                                                // last vertical position of the 1st graph and.......
int lastyPos1= 0;     
int lastyPos2= 0;   
int lastyPos3= 0;   
int lastyPos4= 0;    
int lastyPos5= 0;                                                // ........last vertical position of the 6th graph
String startvals = "'0','0','0','0','0','0'";
int vals[]; 

void setup () {
  size(1024, 300);                                               // set the window size
  println(Serial.list ());                                       // List all the available serial ports
  myPort = new Serial(this, Serial.list()[1], 9600);             //open  second COMport on PC
  myPort.bufferUntil(000);                                       // don't generate a serialEvent() unless you get a 000 (which im not convinced will work)
  background(0);                                                 // set inital background:
//  vals = new int[6];
//  println(vals);
//  String[] vals = (splitTokens(startvals));
                 }
void draw () {
  // draw the line:
  println(vals[0]);                                              // (debug)  visually check the first sensor value
  stroke(300,205, 0);
  line (lastxPos, lastyPos0, xPos,250- vals[0]);                 // draw for sensor one and...
  stroke(30,205, 0);
  line (lastxPos, lastyPos1, xPos,250- vals[1]);
  stroke(300,205, 60);
  line (lastxPos, lastyPos2, xPos,250- vals[2]);
  stroke(300,05, 200);
  line (lastxPos, lastyPos3, xPos,250- vals[3]);
  stroke(300,205, 30);
  line (lastxPos, lastyPos4, xPos,250- vals[4]);
  stroke(300,205, 300);
  line (lastxPos, lastyPos5, xPos,250- vals[5]);                 // .......draw for sensor 6

  lastxPos = xPos;                                               // 
  lastyPos0 = vals[0];   
  lastyPos1 = vals[1];
  lastyPos2 = vals[2];
  lastyPos3 = vals[3];
  lastyPos4 = vals[4];
  lastyPos5 = vals[5];

  if (xPos &gt;= width) {                                           // at the edge of the screen, go back to the beginning:
    xPos = 0;                                                    // reset to start of window 
    lastxPos = 0;                                                // reset to start of window
    background(50);          
  } else {     
    xPos =xPos + 20;                                             // increment the horizontal position:
          }
}


void serialEvent(Serial s) {                                    //*******************************************************
 vals = int(splitTokens(s.readString()));                //***  Divide incoming string to seperate variables   ***
// startvals = splitTokens(",");                             //*** These two lines are previous attempts that      ***
// vals[] = splitTokens(s, ", ");                             //*** didn't seem to work.                            ***
                                                                          //***   ***   ***  ***   ***   ***   ***   ***   ***  ***
  lastyPos0 = (vals[0]);                                        //***    This cant be right, surely                   ***
  lastyPos1 = (vals[1]);                                        //***                                                 ***
  lastyPos2 = (vals[2]);                                        //***  THIS is where I am lost! I am certain this is  ***
  lastyPos3 = (vals[3]);                                        //***  NOT how to do this but I cant find another way ***
  lastyPos4 = (vals[4]);                                        //***  online to do it.                               ***
  lastyPos5 = (vals[5]);                                        //*******************************************************

  redraw = true;
}`
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can anyone help me find what's wrong with my code for a video player based off sensor reading</title>
      <link>https://forum.processing.org/two/discussion/22640/can-anyone-help-me-find-what-s-wrong-with-my-code-for-a-video-player-based-off-sensor-reading</link>
      <pubDate>Wed, 17 May 2017 16:53:23 +0000</pubDate>
      <dc:creator>Tom_Partington</dc:creator>
      <guid isPermaLink="false">22640@/two/discussions</guid>
      <description><![CDATA[<p>I'm fairly new to processing and it's my first time involving videos. I am currently using Arduino and Processing to create touch sensitive video player. I have managed to get Arduino to send the readings to Processing and it is reading them. But I can't get the videos to play properly when a sensor is activated (going from 0&gt;1). I think there might be a few things wrong/missing with the code or certain things in the wrong place. A blank screen currently loads when I run the sketch and doesn't change even when activating the sensors.
I have the video files in a 'data' folder within the sketch folder so I think they are in the right place. Any help at all is greatly appreciated. Code below;</p>

<pre><code>import processing.serial.*;
import processing.video.*;

Movie movie1;
Movie movie2;
Movie movie3;
//etc.

Serial myPort;
int linefeed = 10;   // Linefeed in ASCII
int numSensors = 3;  // we will be expecting for reading data from four sensors (CHANGE)
int sensors[];       // array to read the values
int pSensors[];      // array to store the previuos reading, useful for comparing
// actual reading with the last one

String currentMovie;

void setup() {
  size(1440, 1080);

  println(Serial.list());

  // files inside processing folder for this programme
  movie1 = new Movie(this, "Sun.mp4");
  movie2 = new Movie(this, "Mercury.mp4");
  movie3 = new Movie(this, "Venus.mp4");
  //etc.

  myPort = new Serial(this, Serial.list()[3], 115200);
  // read bytes into a buffer until you get a linefeed (ASCII 10):
  myPort.bufferUntil(linefeed);
}

void draw() {

  // check the sensors and sets the movie to play

  if (currentMovie == "")        //if nothing is playing
  {
    if (sensors[0] == 1)
    {
      //print("Play Movie 1");
      currentMovie = "movie1";
      movie1.play();
    } else if (sensors[1] == 1)
    {
      print("Play Movie 2");
      currentMovie = "movie2";
      movie2.play();
    } else if (sensors[2] == 1)
    {
      print("Play Movie 3");
      currentMovie = "movie3";
      movie3.play();
    }
  } else
  {
    // do nothing (if a movie is playing do nothing)
  }

  // show the movie frames

  if (currentMovie == "movie1")
  {
    if (movie1.available())
    {
      image(movie1, 0, 0);
    } else
    {
      currentMovie = "";    // if a frame is available, show the next frame. This means once the video ends it will play nothing.
    }
  } else if (currentMovie == "movie2")
  {
    if (movie2.available())
    {
      image(movie2, 0, 0);
    } else
    {
      currentMovie = "";
    }
  } else if (currentMovie == "movie3")
  {
    if (movie3.available())
    {
      image(movie3, 0, 0);
    } else
    {
      currentMovie = "";
    }
  }
}

void serialEvent(Serial myPort) {

  // read the serial buffer:
  String myString = myPort.readStringUntil(linefeed);

  // if you got any bytes other than the linefeed:
  if (myString != null) {

    myString = trim(myString);

    // split the string at the commas
    // and convert the sections into integers:

    pSensors = sensors;
    sensors = int(split(myString, ','));

    // print out the values you got:

    for (int sensorNum = 0; sensorNum &lt; sensors.length; sensorNum++) {
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
    }

    // add a linefeed after all the sensor values are printed:
    println();
  }
}

void movieEvent(Movie m) {
  m.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Read multiple serial port</title>
      <link>https://forum.processing.org/two/discussion/22601/read-multiple-serial-port</link>
      <pubDate>Mon, 15 May 2017 18:39:30 +0000</pubDate>
      <dc:creator>bbjodel</dc:creator>
      <guid isPermaLink="false">22601@/two/discussions</guid>
      <description><![CDATA[<p>Sorry kfrajer for my post, publication is correct now</p>

<p>Hi,</p>

<p>i've this code for to read in processing two arduino's separately.</p>

<p>First arduino is a multiples sensors, second arduino have an gps.</p>

<p>My serial data have this format:</p>

<p>For arduino sensors:</p>

<pre><code>    85,89,120
</code></pre>

<p>For arduino gps have this format (gps string)</p>

<p>$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10</p>

<p>Here my code but don't run properly, because i've just Serial portOne run impossible to run two ports...</p>

<pre><code>    import processing.serial.*;

    Serial portOne;    // the first serial port
    Serial portTwo;    // the second serial port


    void setup() {
      size(800, 480);
      // list the serial ports
      println(Serial.list());
      // open the serial ports:
      portOne = new Serial(this, Serial.list()[0], 115200);
      portTwo = new Serial(this, Serial.list()[1], 115200);

      portOne.bufferUntil('\n');
      portTwo.bufferUntil('\n');
    }

    void draw() {

    }

    void serialEvent(Serial thisPort) {
      // read the incoming serial data:
      String input1 = thisPort.readStringUntil('\n');

      if (input1 != null) {
      input1 = trim(input1);
      String[] values1 = split(input1, ",");

        // if the string came from serial port one:
        if (thisPort == portOne) {
          if(values1.length == 3){
      int a1 = int(values1[0]); 
      int a2 = int(values1[1]); 
      int a3 = int(values1[2]);

      print(a1); 
      print(","); 
      print(a2); 
      print(","); 
      println(a3); 

       } 
        }

        // read the incoming serial data:
      String input2 = thisPort.readStringUntil('\n');

       if (input2 != null) {
      input2 = trim(input2);
      String[] values2 = split(input2, ",");

        // if the string came from serial port two:
        if (thisPort == portTwo) {
          if(values2.length == 3){
      int b1 = int(values2[0]); 
      int b2 = int(values2[1]); 
      int b3 = int(values2[2]);

      print(b1); 
      print(","); 
      print(b2); 
      print(","); 
      println(b3); 

       } 
        }

       }
      }
    }
</code></pre>

<p>If someone has an idea please help me.</p>

<p>Regards, and sorry for my english....</p>

<p>Alfred</p>
]]></description>
   </item>
   <item>
      <title>Why is it doing that ??? Saving live capture instead of the content of a capture object</title>
      <link>https://forum.processing.org/two/discussion/22237/why-is-it-doing-that-saving-live-capture-instead-of-the-content-of-a-capture-object</link>
      <pubDate>Thu, 27 Apr 2017 08:31:51 +0000</pubDate>
      <dc:creator>Mat007</dc:creator>
      <guid isPermaLink="false">22237@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,
I am trying to record incoming data from a serial port as well as capturing video. Because of the speed (data is coming every millisecond) I had to trigger the video capture inside the serialEvent (built-in camera works at 30 fps max). I decided to capture a snapshot every 50ms. It takes too long to save the snapshot so I had to buffer it in an arrayList. I did the same with the serial data.
Acquisition is triggered and stopped using keyPressed. Once it is finished, I come back to my arrayLists and save the pictures one by one (including the serial data in the name, it is just a short string).
Here is the trouble: instead of reading the content of the Capture arrayList it reads whatever is coming from the camera.</p>

<p>I tried without success:
-myPort.stop()
-myVideo.stop()
-noLoop()
-using a PImage arrayList instead of Capture object arrayList
-use different ways to trigger/stop acquisition.</p>

<p>It doesn't make any sense to me... why when I write mySnapshotAL.get(i) do I get the current camera view and not the content of the arrayList which is populated properly (I checked the size) ???</p>

<p>Many thanks!!!</p>

<pre><code>import processing.video.*;
import processing.serial.*;

Capture myVideo;                     // declaring a Capture object
Serial myPort;                       // declaring a  serial port
ArrayList&lt;String&gt; myDataAL;          // declaring an ArrayList of String (serial data)
ArrayList&lt;Capture&gt; mySnapshotAL;     // declaring an ArrayList of Capture objects
String myFileName;
String myDataString;
String myDate;
int startTime;
String myTime;
int i=0;
boolean saving=false;

void setup() {  
  frameRate(1000);
  size(1000, 700);
  background(0);
  mySnapshotAL= new ArrayList&lt;Capture&gt;();            // initialising the ArrayList of Capture objets
  myDataAL= new ArrayList&lt;String&gt;();                 // initialising the ArrayList of String
  myVideo = new Capture(this, 320, 240,30);          // initialising the Capture object
  myVideo.start();
  myPort = new Serial(this, Serial.list()[1], 9600); // initialising the port dev/cu.usbmodem1411
  myPort.bufferUntil(10); // char(10) = line feed
}

void serialEvent(Serial myPort) {   // myPort receives data every ms
  i++; 
    if (i==50){
      myVideo.read(); // only acquire every 50 ms
      i=0;
    } 
  myDataString = trim(myPort.readString());
  myTime=nf(millis()-startTime,6,1).substring(0,5);
  myDataString=myTime + "," + myDataString;
  if (saving){
  mySnapshotAL.add(myVideo);
  myDataAL.add(myDataString);
  }
}

void draw() {  
image(myVideo, 600, 40);
}

void keyPressed(){
        if (!saving) {
          saving=true;
          startTime=millis();
          }
        else {
          saving=false;
          myDate= nf(hour(),2,1).substring(0,2) + "h" + nf(minute(),2,1).substring(0,2);
          for (int i =0; i&lt;mySnapshotAL.size(); i++){
              myFileName="VideoFiles/Capture" + i + "@" +myDate+ "-" +myDataAL.get(i)+".png";
              mySnapshotAL.get(i).save(myFileName); 
              if (i==300) break;  // safety, until code is failproof
          }
        }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Reading data from a bluetooth port</title>
      <link>https://forum.processing.org/two/discussion/22396/reading-data-from-a-bluetooth-port</link>
      <pubDate>Thu, 04 May 2017 21:12:02 +0000</pubDate>
      <dc:creator>Mat007</dc:creator>
      <guid isPermaLink="false">22396@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I am trying to read data sent by a nRF51822 Bluetooth LE module (Adafruit Feather M0 Bluefruit LE). I modified the bleuart_datamode sketch given as example to send the same data via bluetooth and USB serial.
I can see the Bluetooth data on my iPad with the Bluefruit LE connect app so I know that my board is sending stuff in the air. Using processing however I can read the serial data but I get a null string from bluetooth.
I suspected a baud rate problem so I tried everything... I don't get any error message though. The code is compiling and running but I get a null string...</p>

<p>Any idea ? Thanks !</p>

<pre><code>import processing.serial.*; 

Serial mySerialPort;          
Serial myBluePort;
PFont myFont;          
String serialString;       
String blueString;
int lf = 10;            // ASCII linefeed aka '/n'

void setup() { 

  frameRate(1000);
  size(400,200); 
  myFont = loadFont("ArialMT-18.vlw");  // Processing&gt;Tools&gt;Create Font 
  textFont(myFont, 18); 
  printArray(Serial.list());  

  mySerialPort = new Serial(this, Serial.list()[1], 115200); 
  mySerialPort.bufferUntil(lf); 

  myBluePort = new Serial(this, Serial.list()[0], 1200); 
  //myBluePort = new Serial(this, Serial.list()[0], 2400); 
  //myBluePort = new Serial(this, Serial.list()[0], 4800); 
  //myBluePort = new Serial(this, Serial.list()[0], 9600); 
  //myBluePort = new Serial(this, Serial.list()[0], 14400);
  //myBluePort = new Serial(this, Serial.list()[0], 19200); 
  //myBluePort = new Serial(this, Serial.list()[0], 28800); 
  //myBluePort = new Serial(this, Serial.list()[0], 38400); 
  //myBluePort = new Serial(this, Serial.list()[0], 57600); 
  //myBluePort = new Serial(this, Serial.list()[0], 76800); 
  //myBluePort = new Serial(this, Serial.list()[0], 115200); 
  //myBluePort = new Serial(this, Serial.list()[0], 230400); 
  //myBluePort = new Serial(this, Serial.list()[0], 250000); 
  //myBluePort = new Serial(this, Serial.list()[0], 460800); 
  //myBluePort = new Serial(this, Serial.list()[0], 921600); 
  //myBluePort = new Serial(this, Serial.list()[0], 1000000); 
   myBluePort.bufferUntil(lf);
} 

void draw() { 

  if ( mySerialPort.available() &gt; 0) serialString = mySerialPort.readString();
  if ( myBluePort.available() &gt; 0) blueString = myBluePort.readString();

  background(0); 
  text("Receiving serial data : " + trim(serialString), 10,20); 
  text("Receiving bluetooth data : " + trim(blueString), 10,40); 

} 
</code></pre>
]]></description>
   </item>
   </channel>
</rss>