<?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/p2/feed.rss?Tag=bufferuntil%28%29</link>
      <pubDate>Sun, 08 Aug 2021 15:35:03 +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>Graph with loop checking for sensor input</title>
      <link>https://forum.processing.org/two/discussion/21693/graph-with-loop-checking-for-sensor-input</link>
      <pubDate>Thu, 30 Mar 2017 00:59:12 +0000</pubDate>
      <dc:creator>cormee38</dc:creator>
      <guid isPermaLink="false">21693@/two/discussions</guid>
      <description><![CDATA[<p>Hi.  I don't have a lot of experience with Processing.  I need a graphical display of the changing values coming from a sensor which I have so far.  I then need to check if the sensor value has dropped below a certain value and has been below that value for 20 seconds, if it has I use a wave file for an alarm.  The problem I am having with this code is;</p>

<ol>
<li><p>The wave alarm is sounding after 20 seconds of running the program, not after 20 seconds of the sensor value being below a certain value "threshold" (fyi - this same code worked properly for me using Arduino)</p></li>
<li><p>Once the wave file plays the graph stops, I would like for the graph to continue displaying the sensor values</p></li>
<li><p>Once the sensor value goes above the "threshold" I would like for the wave file to close and the program to continue monitoring when the sensor value drops below "threshold" for 20 seconds or more.</p></li>
</ol>

<p>Any help would be greatly appreciated.  Thanks!</p>

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

          Minim minim;
          AudioPlayer player;

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

          int threshhold = 200;
          float fValue;
          boolean newVal = false;

          void setup () 
          {
            // set the window size:
            size(800, 600);

            myPort = new Serial(this, "COM9", 9600);

            // don't generate a serialEvent() unless you get a newline character:
            myPort.bufferUntil('\n');

             // set inital background:
            background(0);
            stroke(127, 34, 255);
          }

         void draw () 
         {
          if (newVal) 
          {
            line(xPos, height, xPos, height - fValue);

            if (++xPos &gt;= width) 
            {
              xPos = 0;
              background(0);
            }
            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);
            newVal = true;
          }

        int lastBreath = 0;

            if (fValue &gt; threshhold)
            {
              lastBreath = millis();
            }

            if (fValue &lt; threshhold)
                {
                  if (millis() - lastBreath &gt;= 20000)
                     {
                       while (fValue &lt; threshhold)
                       {
                          minim = new Minim(this);
                          // loadFile will look in all the same places as loadImage does.
                          // this means you can find files that are in the data folder and the 
                          // sketch folder. you can also pass an absolute path, or a URL.
                          // Change the name of the audio file here and add it by clicking on "Sketch —&gt; Import File"
                          player = minim.loadFile("chimes.wav"); 
                          player.play();
                          delay(500);                                   
                       }
                     }
                }
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can I split up serial data into multiple variables</title>
      <link>https://forum.processing.org/two/discussion/22033/how-can-i-split-up-serial-data-into-multiple-variables</link>
      <pubDate>Sun, 16 Apr 2017 13:57:43 +0000</pubDate>
      <dc:creator>EndlessOyster</dc:creator>
      <guid isPermaLink="false">22033@/two/discussions</guid>
      <description><![CDATA[<p>Im sending data from arduino to processing. I have six variables to send. Currently Im doing it through serial and Ive got processing to receive the data, currently it arrvies in processing as 6 lines of data. How can I set it up so I can have 6 variables in processing.</p>
]]></description>
   </item>
   <item>
      <title>Help needed getting Processing to open video files.</title>
      <link>https://forum.processing.org/two/discussion/21748/help-needed-getting-processing-to-open-video-files</link>
      <pubDate>Sat, 01 Apr 2017 17:27:37 +0000</pubDate>
      <dc:creator>harrisonh555</dc:creator>
      <guid isPermaLink="false">21748@/two/discussions</guid>
      <description><![CDATA[<p>hello,</p>

<p>I am wanting to replace the following code. I have a capacitive touch sensor attached to processing that opens up a random image every time the sensor is held, when the sensor is let go this image disappear.</p>

<p>I want to essentially replace the image files with 26 short video clips at 25 frame rate. Im not sure how to change this code to make that happen.</p>

<p>Any help would be great!</p>

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

int threshold = 30; 
PImage [] picArray = new PImage [26]; 
Serial myPort;

boolean holdImage=false;
int imgIndex;

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

  for (int i=0; i&lt;picArray.length; i++)
    picArray[i]=loadImage(i + ".png");

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


void draw() {

  background (255, 255, 255); 
  if (holdImage==true) { 
    image(picArray[imgIndex], 0,0);
  }
}


void serialEvent(Serial myPort) {

  String inString = myPort.readStringUntil('\n');

  if (inString != null) {

    inString = trim (inString);
    float[] touches = float (split(inString, ","));

    if (touches.length &gt;=1) {
      int touch1Value = touches[0] &gt;= threshold ? 1: 0;

      if (touch1Value == 1) {
        if (holdImage == false) {
          imgIndex=int(random(picArray.length));
          holdImage=true;
        }
      } else
        holdImage=false;  //RELEASE holder so to detect next usr press event
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Multiple values chart issue.</title>
      <link>https://forum.processing.org/two/discussion/21242/multiple-values-chart-issue</link>
      <pubDate>Wed, 08 Mar 2017 07:39:34 +0000</pubDate>
      <dc:creator>JsGarage</dc:creator>
      <guid isPermaLink="false">21242@/two/discussions</guid>
      <description><![CDATA[<p>ok, so I got quite a lot more code now, and in the midst of trying to make this graph display 6 sensors worth of data, I've gotten stuck on the part where it strips the string back down into 6 parts(after the arduino put them together, I have tested, and the arduino side works fine.)
I think that part actually may work, but I'm confused as to how to get the stripped string into my existing x/y display.
if what I've messed up is obvious, please just point out where the problem is, not how to fix it.</p>

<p>the basic idea is just a 6 channel datalogger- I've not gotten to the saving parts, I'm still on the displaying live data side of things.</p>

<p>1st data feed is in Hz
Next 4 are just 0-5v
Last one is Digital in</p>

<p>------------------Arduino code------------------</p>

<pre><code>    const uint8_t turboSpdPin = 5; //TurboSpeed Input Digital Pin
    const uint8_t map1Pin = A0; // Map Sensor 1 Input Analog pin
    const uint8_t map2Pin = A1; // Map Sensor 2 Input Analog pin
    const uint32_t oneSecond = 1000000; //Meassured time
    uint32_t timer = 0;
    uint32_t sts = 0;
    const uint32_t c = 1; // wait for 3000 pulses
    uint32_t ets = 0;
    int turboSpdPinState = LOW;
    int turboSpd = 0;
    int prevturboSpdPinState = LOW;
    int map1inputValue = 0;  //set sensor value to 0 
    int map2inputValue = 0;  //set sensor value to 0
    int aux1Value = 0; // set start value to 0
    int aux2Value = 0; // set start value to 0
    const int Aux1 = A2; //Define Aux Input Pin number as Analog 2
    const int Aux2 = A3; //Define Aux Input Pin number as Analog 3
    const int extPwr = 5;
    const int turbineActivity = 6;
    const int map1connected = 7;
    const int map2connected = 8;
    const int pwrOn = 9;



    void setup()
    {
     Serial.begin(115200);
     pinMode(turboSpdPin, INPUT); //Declared Digital Pin 5 as Input
     digitalWrite(turboSpdPin,LOW); 
     }
    void loop() {

      map1inputValue = analogRead(map1Pin);   //read map sensor input
      map2inputValue = analogRead(map2Pin);   //     " "
      aux1Value = analogRead(Aux1);
      aux2Value = analogRead(Aux2);
      pulseIn(turboSpdPin,HIGH);
      sts = micros(); // start time stamp
       for (uint32_t i=c; i&gt;0; i--)
        pulseIn(turboSpdPin,LOW);

     ets = micros(); // end time stamp
     //Serial.print("$");
     Serial.println((c*1e6/(ets-sts))); // output Hz
    }
</code></pre>

<p>-------------------Processing Code---------------------</p>

<pre><code>    void setup () {
      // set the window size:
      size(1024, 300);
    plot = new GPlot(this, 0, 0, 1024, 300);
      // List all the available serial ports
      println(Serial.list ());
      myPort = new Serial(this, Serial.list()[1], 115200); //open COMport(3) on PC
      myPort.bufferUntil('\r'); // don't generate a serialEvent() unless you get a carriage return
      background(0);    // set inital background:
                     }
    void draw () {
      // draw the line:
      stroke(lastyPos,205, 0);
      line(lastxPos, height-(lastyPos+20), xPos, height - (inByte+20));
      lastxPos = xPos;
      lastyPos =inByte; // (int)inByte;


      if (xPos &gt;= width) {                                      // at the edge of the screen, go back to the beginning:
       inByte=0;                                                //drop x/y to bottom of window
        line(lastxPos, height-lastyPos+20, xPos, height-20);    // bring x/y back to start of window

        xPos = 20;               //reset
        lastxPos = 20;           //reset
         background(0);          
      } else {     
        xPos =xPos + 3;   // increment the horizontal position:
              }
    }


    void serialEvent (Serial myPort) {

      String inString = myPort.readStringUntil('\r');    // read serial buffer:
      if (inString != null) {
           inString = trim(inString);          // trim off any whitespace:
       //next 4 lines worked as one data feed, everything after that was (i think ) added from another sketch to try to make a 6 value feed. I am stuck here.

       // convert to an int and map to the screen height:
       // inByte = float(inString);
       // println(inByte);
       // inByte = map(inByte, 0, 1023, 0, height-20);
       int mysensors[] = int(split(inString, '\t'));
        count = mysensors.length;
     println(mysensors.length);
        for (int i=0; i&lt;count; i++)  //
        {
          // set sensor[i] value for use in draw()
          sensors[i] = mysensors[i];   //&lt;--- you'll need to change this line to put
                                                 //    the values where you want them
          // print out the values we got:
          print(i + ": " + sensors[i] + "\t");
        }
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Two sensors trigger same part of code</title>
      <link>https://forum.processing.org/two/discussion/21447/two-sensors-trigger-same-part-of-code</link>
      <pubDate>Fri, 17 Mar 2017 03:27:40 +0000</pubDate>
      <dc:creator>Julo</dc:creator>
      <guid isPermaLink="false">21447@/two/discussions</guid>
      <description><![CDATA[<p>I am using two pressure sensors with arduino to receive two sets of values so I can trigger different things on the screen, but the two sensors keep only triggering the same part of code, I think it's the port problem but couldn't figure it out.</p>

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

int linefeed;
int count;
int sensors[];
int a,b,c;

int lf0 = 10;
int lf1 = 10;

String myString0 = null;
String myString1 = null;
Serial myPort0;
Serial myPort1;
float pressureSession0num, pressureSession1num;

void setup() {
  myPort0 = new Serial(this, Serial.list()[0], 9600);
  myPort1 = new Serial(this, Serial.list()[1], 9600);
  myPort0.clear();
  myPort1.clear();
  fullScreen();
  smooth();
}

void draw() {
  background(0);
  while (myPort0.available() &gt; 0) {
    myString0 = myPort0.readStringUntil(lf0);
    if (myString0 != null) {
      pressureSession0num=float(myString0);  
      println("1P"+pressureSession0num);
    }
  }
  myPort0.clear();

  while (myPort1.available() &gt; 0) {  
    myString1 = myPort1.readStringUntil(lf1);
    if (myString1 != null) {
      pressureSession1num=float(myString1);  
      println("2P"+pressureSession1num);
    }
  }
  myPort1.clear();
}
  void counter() {
    if (pressureSession0num&gt;500) {
      a += 1;
    }
    if (pressureSession1num&gt;500) {
      b += 1;
    }
  }
</code></pre>

<p>Arduino code</p>

<pre><code>int analogPin0 = 0;
int analogPin1 = 1;

float temp0=0;
float temp1=0;

void setup() { 
  Serial.begin(9600);
} 

void loop() {
  temp0=analogRead(analogPin0);
  temp1=analogRead(analogPin1);

  Serial.println(temp0); // println add Linefeed to my float
  Serial.println(temp1); // println add Linefeed to my float

  delay(250);
}  
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to make an oscilloscope display</title>
      <link>https://forum.processing.org/two/discussion/21014/how-to-make-an-oscilloscope-display</link>
      <pubDate>Sun, 26 Feb 2017 10:48:18 +0000</pubDate>
      <dc:creator>Peter_Harwood</dc:creator>
      <guid isPermaLink="false">21014@/two/discussions</guid>
      <description><![CDATA[<p>It would be really useful to have a virtual oscilloscope for a current Arduino project.  Here is an attempt at plotting a serial input from an Arduino which continuously sends the output of a pot.  It takes 25 seconds to plot the 1600 points across the screen.  Anything less than a second would be good.  Any ideas?</p>

<p><code>import processing.serial.*; // imports library.  Unlike Arduino, not auto
Serial port;  //defines serial object as 'port'
float potvalue = 0; //This is the value in the range 0-255 to be read
int i = 0;
//float yvalues[]=new float[width+1];
void setup ()
{
  background(255);
    size(1600, 500);
  port = new Serial(this, "COM3",9600); //Opens the port being used and sets rate
  port.bufferUntil('\n');
}
void draw(){
  if (i&gt;=1600){
    i=0;
    background(255);
  }
  fill(0);
 point(i,375-potvalue);
 i=i+1;
}
void serialEvent (Serial port)
{
  potvalue = float(port.readStringUntil('\n')); 
}</code></p>

<p>This is the Arduino Test program:</p>

<p>`int potPin = 0;</p>

<p>void setup()
{
  Serial.begin(9600);
}</p>

<p>void loop()
{
  int val = map(analogRead(potPin), 0, 1023, 0, 255);
  Serial.println(val);
}`</p>
]]></description>
   </item>
   <item>
      <title>How to add a second soundfile</title>
      <link>https://forum.processing.org/two/discussion/21220/how-to-add-a-second-soundfile</link>
      <pubDate>Tue, 07 Mar 2017 11:00:35 +0000</pubDate>
      <dc:creator>beej</dc:creator>
      <guid isPermaLink="false">21220@/two/discussions</guid>
      <description><![CDATA[<p>I am using an accelerometer to control the rate of a sound but I want to add a second sound that is only triggered when currentX value is greater than 350 for a delay of 3 seconds, I have got the first sound working as I want it, but when I tried adding the second sound as part of an array it all stopped working.</p>

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

import processing.serial.*;
import processing.opengl.*;
Serial myPort;
int baudRate = 9600;
//int lf = 10;


int[] xAxis;
int[] yAxis;
int[] zAxis;

SoundFile file;

int currentX = 0;
int currentY = 0;
int currentZ = 0;

int rateX =1;
int ampY =1;
int addZ =1;

int totalReadings = 400;
int readingPos = 0; // the reading position in the array

void setup() {
  smooth();
  size(600, 300); 
  //file = new SoundFile(this, "magic-chime-02.mp3");
  // file = new SoundFile(this, "magic-chime-04.mp3");
  file = new SoundFile(this, "Blastwave_FX_MagicWindChimesHarp_SFXB.36.mp3");

  file.loop();



  xAxis = new int[totalReadings];
  yAxis = new int[totalReadings];
  zAxis = new int[totalReadings];



  myPort = new Serial(this, "com5", baudRate);
  myPort.bufferUntil(10);

  noLoop();
}

void serialEvent(Serial p) {
  String inString;

  try {
    inString = (myPort.readString());
    currentX = xValue(inString);
    currentY = yValue(inString);
    currentZ = zValue(inString);

  }
  catch(Exception e) {
    println(e);
  }
  redraw();
}

void draw()
//alter the pitch rate and amp depending on xyz values
{
  file.play();
  file.rate(rateX);
  file.amp(ampY);
  file.add(addZ);
  //println( "current"+ currentX, currentY, currentZ);
  rateX = currentZ/100;
  ampY = currentX/100;
  addZ = currentY/100;
  println(rateX);
  println(ampY);
  println(addZ);

//stop the sound if x is less than 350 
  if (currentX &lt; 350) {
    file.play();
    println("Play");
  } else {
    file.stop();
    println("Stop");
    // delay(10);
  }
  delay(500);
}



int xValue(String inString) {
  int pipeIndex = inString.indexOf('|');
  return int(inString.substring(0, pipeIndex));
}

int yValue(String inString) {
  int pipeIndex = inString.indexOf('|');
  int colonIndex = inString.indexOf(':');
  return int(inString.substring(pipeIndex+1, colonIndex));
}

int zValue(String inString) {
  int colonIndex = inString.indexOf(':');
  return int(inString.substring(colonIndex + 1, inString.length() - 2));
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>I'm trying to make a graph -Part 1</title>
      <link>https://forum.processing.org/two/discussion/21101/i-m-trying-to-make-a-graph-part-1</link>
      <pubDate>Thu, 02 Mar 2017 13:08:54 +0000</pubDate>
      <dc:creator>JsGarage</dc:creator>
      <guid isPermaLink="false">21101@/two/discussions</guid>
      <description><![CDATA[<p>im trying to make a graph (added to the bottom of this post) with data acquired by a serial feed
But it won't draw right no matter how many variables I tweak.</p>

<p>I am not asking anyone to code for me, just to point out to a first timer(usually play with arduino) where my problem lies.</p>

<p>here is my code:`</p>

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


Serial myPort;        // The serial port
float inByte = 0;     // defines starting value for the serial input
int xPos = 1;         // horizontal position of the graph
int yPos = 300;         // current vertical position of the graph
int lastxPos = xPos;     // previous horizontal position of the graph
float lastyPos = (inByte);     // last vertical position of the graph


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

  // List all the available serial ports
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list ());

  // I know that the first port in the serial list on my mac
  // is always my  Arduino, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[1], 115200);

  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');

  // set inital background:
  background(0);
}
void draw () {
  // draw the line:
  stroke(0, 205, 0);
  line(xPos, height-lastyPos*5, xPos, height - inByte*5);



  // at the edge of the screen, go back to the beginning:
  if (xPos &gt;= width) {
    xPos = 0;
    background(0);
  } else {


     // increment the horizontal position:
    xPos =xPos + 10;
    //lastxPos = xPos;

  }
}


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

  if (inString != null) {
    // trim off any whitespace:
   inString = trim(inString);
    // convert to an int and map to the screen height:
    inByte = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height);
  }
}
</code></pre>

<p>`
<img src="https://forum.processing.org/two/uploads/imageupload/580/E8BB3KQC8CMW.jpg" alt="dammit" title="dammit" /></p>
]]></description>
   </item>
   <item>
      <title>EtchAsketch code modification</title>
      <link>https://forum.processing.org/two/discussion/20685/etchasketch-code-modification</link>
      <pubDate>Mon, 06 Feb 2017 15:04:24 +0000</pubDate>
      <dc:creator>trinity</dc:creator>
      <guid isPermaLink="false">20685@/two/discussions</guid>
      <description><![CDATA[<p>I am working on a science project with my son that involves generating a force as a function of time plot. My idea is to modify the LittleBits EtchAsketch code for this purpose. Accordingly, I would like to know how I could modify the EtchAsketch processing code to measure time along the x-axis. Moreover, I would like to show the numerical values on the vertical and horizontal axes and keep the measured signal. The LittleBits Arduino is based on the Lenoardo board. Any help is welcome. Thanks!</p>
]]></description>
   </item>
   <item>
      <title>No stable recieving of Data from two MPU 6050</title>
      <link>https://forum.processing.org/two/discussion/20657/no-stable-recieving-of-data-from-two-mpu-6050</link>
      <pubDate>Sun, 05 Feb 2017 13:56:48 +0000</pubDate>
      <dc:creator>Patrik9</dc:creator>
      <guid isPermaLink="false">20657@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>i'm interested in displaying the roll and pitch angles in processing. My Arduino code is from</p>

<p><a rel="nofollow" href="https://github.com/eadf/MPU6050_DMP6_Multiple">https://github.com/eadf/MPU6050_DMP6_Multiple</a></p>

<p>According to that I defined the output of the <strong>arduino code</strong> and in the serial monitor everything looks fine :).  I deleted the line OUTPUT_SERIAL.print("pr:"); so that just a 0 or 1 is send for the identification of the mpu, then TAB Angle1 for current mpu, TAB Angle2 for current mpu:</p>

<pre><code> OUTPUT_SERIAL.print(mpu); OUTPUT_SERIAL.print("\t");
 OUTPUT_SERIAL.print(ypr[1] * 180 / M_PI);
 OUTPUT_SERIAL.print("\t");
 OUTPUT_SERIAL.println(ypr[2] * 180 / M_PI);
</code></pre>

<p>(Interrupt pins not used as recommended by the way)</p>

<p>The <strong>Code for Processing is below</strong> . I just want to print the values in the console first, sometimes the real values are printed sometimes just zeros appear. Is the Problem the Character which needs to send to start the DMPs or something else (Transmitting led of the arduino not blinking in the case of zeros)?</p>

<pre><code>import processing.serial.*;
Serial myPort;  // Create object from Serial class
String inString;     // Data received from the serial port
int interval = 0;
int     lf = 10; 

float imu0[] = new float[2];
float imu1[] = new float[2];

void setup()
{

  size(800, 600);
  String portName = "COM3";
  myPort = new Serial(this, portName, 115200);
  myPort.clear();
  myPort.bufferUntil(lf);
  myPort.write('r');
}

void draw()
{ background(25);

 if (millis() - interval &gt; 1000) {
        // resend single character to trigger DMP init/start
        // in case the MPU is halted/reset while applet is running
        myPort.write('r');
        interval = millis();}


println(imu0[0]);
println(imu0[1]);
println(imu1[0]);
println(imu1[1]);

}

void serialEvent(Serial p) {
  inString = myPort.readString();

  try {
    // Parse the data
    //println(inString);
    String[] dataStrings = split(inString, '\t');
    if (dataStrings.length == 3) {
      if (dataStrings[0].equals("0")) {
        for (int i = 0; i &lt; dataStrings.length - 1; i++) {
          imu0[i] = float(dataStrings[i+1]);
        }
      } else if (dataStrings[0].equals("1")) {
        for (int i = 0; i &lt; dataStrings.length - 1; i++) {
          imu1[i] = float(dataStrings[i+1]);
        }        
      } else {
        println(inString);
      }
    }
  } catch (Exception e) {
    println("Caught Exception");
  }

}
</code></pre>

<p>If you don't know but have a stable example of recieving data from two mpu 6050 that would be also a big help
Thank you</p>
]]></description>
   </item>
   <item>
      <title>Triggering multiple videos / stuttering / poor performance</title>
      <link>https://forum.processing.org/two/discussion/20512/triggering-multiple-videos-stuttering-poor-performance</link>
      <pubDate>Sat, 28 Jan 2017 13:51:23 +0000</pubDate>
      <dc:creator>jules11</dc:creator>
      <guid isPermaLink="false">20512@/two/discussions</guid>
      <description><![CDATA[<p>Bonjour lovely knowledgeable people,</p>

<p>I have a little problem with playing back videos in processing. The aim is to trigger the videos via an serial port input which works fine. The problem is that the videos are played back very laggy. I assume its because they are somehow all played back in the background. The videos are very short 2-5 seconds, but are in HD (1920x1080) and .H264 coded. They are supposed to be played back as long as the input signal is there, and fade to black when its gone.  Can you please help me figure out how to avoid this problem and achieve fluid playback of the videos? That would be superb! I Have been hammering over this code for a while and I cant figure it out. Annnd, do you have any idea how to implement fading in and fading out of the videos? Tried it with tint, but can not manage it to do it fast enough. You would be a life saver! Merci, merci bien — any help is appreciated!</p>

<p>Love ❤️ jules</p>

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

Movie[]  movie = new Movie[10]; 
float[] myArray = new float[10];
short videoSpeed= 0 ; 
PImage bg;
PImage logo;
short videoID = 9; 

String[] video ={ "modellblinker1.mp4", 
          "modellblinker2.mp4",
          "modellhood.mp4",
          "modellside2.mp4",
          "modellside1.mp4",
          "modellwindshieldsback.mp4",
          "modellTrunk.mp4",
          "modellwindshieldsback.mp4",
          "modellroof.mp4"};



void setup() {
  fullScreen();
  iniMovies();
  imageMode(CENTER);
  frameRate(25);
  bg = loadImage("1.jpg");
  logo = loadImage("m.png");
  println(Serial.list()[0]);
  myPort = new Serial(this, Serial.list()[0], 19200);
  myPort.bufferUntil('\n');


}
void draw() {
  background(0);
  iniMovies();
  mngMovie();

 if( videoID ==9 ){


    image(logo,-57,-57);//, displayWidth/2, displayHeight/2);

  }else{
    image(movie[videoID], displayWidth / 2, displayHeight / 2);
    if (videoID != 9)
       movie[videoID].loop();
  }
}
void movieEvent(Movie m) {
  m.read();
}
void iniMovies(){
   for (int i = 0 ; i&lt; 9;i++){
       movie[i] =  new Movie(this,video[i]);
   }
}  
void mngMovie(){
 // print(myArray);

 if(  myArray[0] &gt;2000.0 ) {  /// blinker link 
   if ( videoID != 0  &amp;&amp; videoID!=9 )      
     movie[videoID].stop();
    movie[0].play();
    videoID = 0; 
 }
 else if(  myArray[1]&gt;-4000.0 ) {  // blinker recht 
   if ( videoID != 1 &amp;&amp; videoID!=9 )      
     movie[videoID].stop();
    movie[1].play();
    videoID = 1; 
 }

 else if(  myArray[2] &lt;-25000.0  || myArray[2] &gt;17000.0  ) {  //  motor 
   if ( videoID != 2  &amp;&amp; videoID!=9)      
     movie[videoID].stop();
    movie[2].play();
    videoID = 2; 
 }

 else if(  myArray[3] &gt;5000.0 ) {  // Tür recht 
   if ( videoID != 3 &amp;&amp; videoID!=9)      
     movie[videoID].stop();
    movie[3].play();
    videoID = 3; 
 }

 else if(  myArray[4] &gt;20000.0 ) {  // Tür links 
   if ( videoID != 4 &amp;&amp; videoID!=9 )      
     movie[videoID].stop();
    movie[4].play();
    videoID = 4; 
 }

 else if(  myArray[5]&gt;20000.0 || myArray[5]&lt;-25000.0) {   // Windschutz 
   if ( videoID != 5 &amp;&amp; videoID!=9 )      
     movie[videoID].stop();
    movie[5].play();
    videoID = 5; 
 }

 else if(  myArray[6] &gt;3000.0 ) { // coffer
   if ( videoID != 6  &amp;&amp; videoID!=9)      
     movie[videoID].stop();
    movie[6].play();
    videoID = 6; 
 }
 else if(  myArray[7] &gt;22000.0|| myArray[7]&lt;-22000.0 ) {  // Fenester hinten
   if ( videoID != 7 &amp;&amp; videoID!=9)      
     movie[videoID].stop();
    movie[7].play();
    videoID = 7; 
 }
 else if(  myArray[8]&lt;-22000.0 ) {  // Dach 
   if ( videoID != 8 &amp;&amp; videoID!=9  )      
     movie[videoID].stop();
    movie[8].play();
    videoID = 8; 
 }

 else {
   if( videoID != 9) 
       movie[videoID].stop();
  videoID=9;
 }
}
void serialEvent(Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');
 if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // split the string on the commas and convert the
 // resulting substrings into an integer array:
 try{
  myArray =  float(split(inString, ";"));
  mngMovie();
   for (int i = 0 ; i&lt; 9 ; i++){
     print(myArray[i]); 
     print(";");
   }
  println(videoID);
 }
 catch(Exception e){
       // println("Error parsing:");
     //      for (int i = 0 ; i&lt; 9 ; i++){
  //   print(myArray[i]); 
  //  print(";");
  // }
   println();
  //println(videoID);
   //     e.printStackTrace();
    }
 }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>got crazy with array...</title>
      <link>https://forum.processing.org/two/discussion/20519/got-crazy-with-array</link>
      <pubDate>Sat, 28 Jan 2017 19:49:26 +0000</pubDate>
      <dc:creator>Ispa</dc:creator>
      <guid isPermaLink="false">20519@/two/discussions</guid>
      <description><![CDATA[<p>hello everyone..... im new to processing and found first problem..... sorry if i ask simple question but i cant understand this...</p>

<p>i got this code:</p>

<pre><code>import processing.serial.*;
 Serial myPort;
 String PORT;
 String result[];

void setup()
{
size(800, 200);
myPort = new Serial(this, Serial.list()[3], 9600);              
//COM that your arduino is on. Mine is on COM22
myPort.bufferUntil('\n');  
}

void serialEvent (Serial myPort)                    //when data is received
{
 PORT = (myPort.readStringUntil('\n'));          //read to the end of the line
 result = split(PORT, ',');
}

void draw()
{
    background(0,0,40);
    fill(255);
    textSize(20);
    textAlign(RIGHT);
    text("Valore Riserva: ", 200, height/2);
    text(result[0], 220, height/2);
    text("Valore Medio: ", 450, height/2);
    //text(result[1], 470, height/2);
    text("Valore Pieno: ", 700, height/2);
    //text(result[2], 720, height/2);
    for ( int i = 0; i &lt; result.length; i = i+1){
      print("index ", i+" : ");
      println(result[i]);
    }
   printArray(result);
}
</code></pre>

<p>and i got this result on console:</p>

<pre><code>index  0 : 1
index  1 : 1
index  2 : 1
index  3 : 

[0] "1"
[1] "1"
[2] "1"
[3] ""
</code></pre>

<p>everything seems to work but when i call an index like this way:</p>

<p>print(result[1]);</p>

<p>it returns me this error:</p>

<p>ArrayIndexOutOfBoundsException:1</p>

<p>like i was calling an unexisting array element......</p>

<p>am i doing something wrong?</p>
]]></description>
   </item>
   <item>
      <title>I'm trying to use this code, but it seems that it might be "out-dated".</title>
      <link>https://forum.processing.org/two/discussion/20367/i-m-trying-to-use-this-code-but-it-seems-that-it-might-be-out-dated</link>
      <pubDate>Fri, 20 Jan 2017 03:44:55 +0000</pubDate>
      <dc:creator>Franco_Maranon</dc:creator>
      <guid isPermaLink="false">20367@/two/discussions</guid>
      <description><![CDATA[<p>This is the code I am trying to run in <em>Processing 3.0.1</em> but it doesn't seem to work. It might be optimized for an older version of <em>Processing</em>, but I'm new to this software and don't exactly know how to use it. Please help, I need this to work for a school project.</p>

<pre><code> /*
  Fiber Optic Grapher - Used with Processing
  Developed/Edited by Arduino and iScience
  More info at instructables.com
*/

import processing.serial.*;

 Serial Port;
 int xPosition = 1;

 void setup () {
 size(600, 300);        

//Serial Port Manager
 println(Serial.list());

 Port = new Serial(this, Serial.list()[0], 9600);
 Port.bufferUntil('\n');

 // set background:
 background(0);

 }
 void draw () {

 }

 void serialEvent (Serial Port) {

 String inString = Port.readStringUntil('\n');

 if (inString != null) {
   inString = trim(inString);
   float inByte = float(inString); 
   inByte = map(inByte * 3 + 250, 0, 1023, 0, height);

   // draw line:
   stroke(500,0,0);
   line(xPosition, height - inByte, xPosition,height - inByte);

   if (xPosition &gt;= width) {
     xPosition = 0;
     background(0); 
   } 
   else
     xPosition++;
 }
 }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Code only working in Processing 2</title>
      <link>https://forum.processing.org/two/discussion/20212/code-only-working-in-processing-2</link>
      <pubDate>Thu, 12 Jan 2017 06:35:11 +0000</pubDate>
      <dc:creator>MaxM4X</dc:creator>
      <guid isPermaLink="false">20212@/two/discussions</guid>
      <description><![CDATA[<p>Hello!
Why is this code not working in processing 3?
I would just run it with processing 2, however I need to run it on a raspberry pi.</p>

<p>What part of the code is incompatible / what has to be changed to make it work?</p>

<p>Thanks!</p>

<pre><code>    /******************************************************************************
    Heart_Rate_Display.ino
    Demo Program for AD8232 Heart Rate sensor.
    Casey Kuhns @ SparkFun Electronics
    6/27/2014
    <a href="https://github.com/sparkfun/AD8232_Heart_Rate_Monitor" target="_blank" rel="nofollow">https://github.com/sparkfun/AD8232_Heart_Rate_Monitor</a>

    The AD8232 Heart Rate sensor is a low cost EKG/ECG sensor.  This example shows
    how to create an ECG with real time display.  The display is using Processing.
    This sketch is based heavily on the Graphing Tutorial provided in the Arduino
    IDE. <a href="http://www.arduino.cc/en/Tutorial/Graph" target="_blank" rel="nofollow">http://www.arduino.cc/en/Tutorial/Graph</a>

    Resources:
    This program requires a Processing sketch to view the data in real time.

    Development environment specifics:
        IDE: Arduino 1.0.5
        Hardware Platform: Arduino Pro 3.3V/8MHz
        AD8232 Heart Monitor Version: 1.0

    This code is beerware. If you see me (or any other SparkFun employee) at the
    local pub, and you've found our code helpful, please buy us a round!

    Distributed as-is; no warranty is given.
    ******************************************************************************/

    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()[2], 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>
]]></description>
   </item>
   <item>
      <title>How to send numbers to my arduino via processing</title>
      <link>https://forum.processing.org/two/discussion/19802/how-to-send-numbers-to-my-arduino-via-processing</link>
      <pubDate>Sun, 18 Dec 2016 08:46:17 +0000</pubDate>
      <dc:creator>Jennifer96</dc:creator>
      <guid isPermaLink="false">19802@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,</p>

<p>my arduino code works but i have problems with my processing code.
The code should gather one number from my website and send it to the arduino.
It doesnt work sadly the way my processing code is written at the moment.
Maybe you guys can take a look and help me with it.</p>

<p>Processing Code:</p>

<pre><code>import processing.serial.*;
Serial ComPort;
String input[];
void setup(){

String portName = Serial.list() [0];
ComPort = new Serial(this, portName, 9600);
ComPort.bufferUntil('\n');
input = loadStrings("website-adresse");
if(input.length != 0){
String s_current = input[0];
int current = Integer.parseInt(s_current);
println(current);
delay(2000);
ComPort.write(current);
}
}
</code></pre>

<p>Arduino Code:</p>

<pre><code>void setup() {
  Serial.begin(9600);  // Baudrate, muss mit PC übereinstimmen
  pinMode(13,OUTPUT);
}
void loop() {
  int c = Serial.read();
  switch (c) {
  case -1: return; // nichts neues gekommen, loop sofort beenden 
  case '0' :
      digitalWrite(13, LOW);
      break;
  case '1' :
      digitalWrite(13, HIGH);
      break;
  }
}
</code></pre>

<p>Greetings Jenni</p>
]]></description>
   </item>
   <item>
      <title>playing multiple tracks at the same time and adjusting volume</title>
      <link>https://forum.processing.org/two/discussion/19287/playing-multiple-tracks-at-the-same-time-and-adjusting-volume</link>
      <pubDate>Fri, 25 Nov 2016 03:03:16 +0000</pubDate>
      <dc:creator>kena1226</dc:creator>
      <guid isPermaLink="false">19287@/two/discussions</guid>
      <description><![CDATA[<p>This is for an art project. 
I'm trying to play 4 wav. files on an infinite loop at the volume 0.
when I press a button, the volume should rise up to 100.
each button is connected with a wav. file, so when I press button A, file A's volume would rise to 100.
I hope this makes things clear enough?</p>

<p>This is the ARDUINO code, I only have 2 wav files at the moment.</p>

<pre lang="c">
  int ledPin = 2;
  int ledPin3 = 3;
  int value = 0;

  void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, INPUT);
  pinMode(ledPin3, INPUT);
 
}
 
void loop()
{
  if (digitalRead(ledPin) == HIGH)
  {
    Serial.println("1");
    delay (50);
  }
  else
  {
   Serial.println("2");
   delay (50);
  }

    if (digitalRead(ledPin3) == HIGH)
  {
    Serial.println("3");
    delay (50);
  }
  else
  {
   Serial.println("4");
   delay (50);
  }
 
  
}

</pre>

<p>This is the PROCESSING file, also with two files.</p>

<pre lang="java">
import ddf.minim.*;
import processing.serial.*;
 
Serial port;
float value = 0;
float old = 0;
 
Minim minim;
AudioPlayer player;


 
void setup()
{
  size(50,50);

  minim = new Minim(this);
  player = minim.loadFile("harp.wav");
  player.play();
  player.shiftGain(-80,-80,100);
  player.rewind();

 
  port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
  port.bufferUntil('\n');
}
 
void draw()
{
  background(0);
  if ((value == 1) || (value == 2))
  {
  if (value != old)
  { 
  if (value == 1)
  {
    //volume up
    player.shiftGain(-80, 0, 100);
    
  }
 else if (value == 2)
 {
   //volume down
   player.shiftGain(0,-80,100);
  
 }
 
  }
 old = value;
 
}
}
void serialEvent (Serial port)
{
  value = float(port.readStringUntil('\n'));
}`

</pre>

<pre lang="java">

This is PROCESSING file version B, 

`import ddf.minim.*;
import processing.serial.*;
 
Serial port;
float value = 0;
 
Minim minim;
Minim minim2;
AudioPlayer player;
AudioPlayer player2;

 
void setup()
{
  size(50,50);

  minim = new Minim(this);
  player = minim.loadFile("basses.wav");
  player.play();
  player.mute();
  player.rewind();
  
  minim2 = new Minim(this);
  player2 = minim2.loadFile("harp.wav");
  player2.play();
  player2.mute();
  player2.rewind();
 
 
  port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
  port.bufferUntil('\n');
}
 
void draw()
{
  background(0);
  if (value == 2)
  {
    player.unmute();
    delay(3000);
    
  }
 if (value == 1);
 {
   player.mute();
   delay(3000);
  
 }
 
   if (value == 4)
  {
    player2.unmute();
    delay(3000);
    
  }
 if (value == 3);
 {
   player2.mute();
   delay(3000);
  
 }
 
}

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

</pre>

<p>The problem is that
a) files are not playing at the same time
b) it's clicking when the button is pressed
c) overall, it's not really responding to the button, just playing on and off by itself.
Any ideas or an easier way to do this maybe?
I really appreciate it.</p>
]]></description>
   </item>
   <item>
      <title>Horizontal scrolling</title>
      <link>https://forum.processing.org/two/discussion/19168/horizontal-scrolling</link>
      <pubDate>Sun, 20 Nov 2016 00:44:03 +0000</pubDate>
      <dc:creator>aster94</dc:creator>
      <guid isPermaLink="false">19168@/two/discussions</guid>
      <description><![CDATA[<p>hello, i would like to add a horizontal scolling bar to this sketch since i "lost" some data at the end of the windows</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/683/2XVEWGDYBNHW.jpg" alt="partialSave" title="partialSave" /></p>

<p>i can't use the example in the reference since it uses an immage. Really i tried to use it but without good results. any idea? maybe i miss a library that could help me?</p>
]]></description>
   </item>
   <item>
      <title>Looping recorded sounds with minim...</title>
      <link>https://forum.processing.org/two/discussion/19238/looping-recorded-sounds-with-minim</link>
      <pubDate>Wed, 23 Nov 2016 11:23:33 +0000</pubDate>
      <dc:creator>Nilan974</dc:creator>
      <guid isPermaLink="false">19238@/two/discussions</guid>
      <description><![CDATA[<p>Hi
I want to record sounds (multiple sounds which should be stored in a folder) with a microphone and loop it with the other sounds I have added - song, song 2 and song 3. The problem is I want the software to initialize and loop the recorded sound by itself, so even if I shut down the program and start it up again, it should continue from where I left. 
Thanks in advance.</p>

<p>`import processing.serial.*; //Importing serial library
import ddf.minim.*; //Importing minim library. Minim is the library we are using for sound-related activities, such as record and playback.</p>

<p>Serial myPort;</p>

<p>Minim minim;</p>

<p>AudioPlayer song; 
AudioPlayer song2;
AudioPlayer song3;</p>

<p>AudioInput in;
AudioRecorder recorder;</p>

<p>int countname; //change the name
int name = 000000;
int startGain = 0;</p>

<p>void newFile()
{<br />
 countname = (name + 1);
 recorder = minim.createRecorder(in, "Rec" + countname + ".wav", true);
}</p>

<p>void setup()
{
  size(120, 120);</p>

<p>//println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');</p>

<p>minim = new Minim(this);</p>

<p>in = minim.getLineIn(Minim.STEREO, 2048);
  newFile();//go to change file name</p>

<p>song = minim.loadFile("beyonce.mp3");
  song2 = minim.loadFile("dajam.wav");
  song3 = minim.loadFile("Rec1.wav");
}</p>

<p>void draw()
{
   background(0); 
   stroke(255);</p>

<p>if ( recorder.isRecording() )
   {
     text("Currently recording...", 5, 15);
     ellipse(60,60,55,55);
     fill(255,0,0);
   }
   else
   {
     text("    Not recording.", 5, 15);
     ellipse(60,60,55,55);
     fill(0,255,0);
   }
}</p>

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

<p>if (inString != null) {
    inString = trim (inString);</p>

<pre><code>float inByte = float(inString); 
println(inByte);

if (inByte == 1){
  song.loop();
  song2.loop();
  song3.loop();
  song.rewind();
  song2.rewind();
  song3.rewind();
}

if (inByte == 0){
  song.pause();
  song2.pause();
  song3.pause();
  song.rewind();
  song2.rewind();
  song3.rewind();
}
</code></pre>

<p>if (inByte == 2){
      if ( recorder.isRecording() ) 
      {<br />
      recorder.endRecord();</p>

<pre><code>  name++; 
  recorder.save();
  println("Done saving.");
  println(name);
  }
  else 
  {
  newFile();
  recorder.beginRecord();
  }
}
</code></pre>

<p>if (inByte == 3){
     song.setGain(startGain++ * 2);
     song2.setGain(startGain++ * 2);
     song3.setGain(startGain++ * 2);
    }</p>

<pre><code>if (inByte == 4){
 song.setGain(startGain-- * 2);
 song2.setGain(startGain-- * 2);
 song3.setGain(startGain-- * 2);
}
</code></pre>

<p>}
}</p>

<p>void stop()
{
 // always close Minim audio classes when you are done with them
 in.close();
 minim.stop();</p>

<p>super.stop();
}`</p>
]]></description>
   </item>
   <item>
      <title>Spin Arrow when inByte == "X" read.</title>
      <link>https://forum.processing.org/two/discussion/19050/spin-arrow-when-inbyte-x-read</link>
      <pubDate>Tue, 15 Nov 2016 11:17:11 +0000</pubDate>
      <dc:creator>valiaugalukas</dc:creator>
      <guid isPermaLink="false">19050@/two/discussions</guid>
      <description><![CDATA[<p>Hi, Im pretty new to processing, I have a sketch which I figured out before.
It reads for incoming bytes coming from arduino.</p>

<p>I've used it before to trigger sounds.
Which was fine triggering them within method where the bytes are read.</p>

<p>I am trying to make it now spin an arrow.</p>

<p>I have setup a function for 'spinning an arrow' which I then can use in 'draw', however, I don't know how to make a statement saying inByte read in 'void serialEvent(Serial myPort)' should trigger 'spin();' in 'void draw()'. 
Hope it makes sense and please please help me.</p>
]]></description>
   </item>
   <item>
      <title>URGENT in need of help with processing code SRF10 ultrasonic sensor</title>
      <link>https://forum.processing.org/two/discussion/18922/urgent-in-need-of-help-with-processing-code-srf10-ultrasonic-sensor</link>
      <pubDate>Mon, 07 Nov 2016 15:16:41 +0000</pubDate>
      <dc:creator>karipuff</dc:creator>
      <guid isPermaLink="false">18922@/two/discussions</guid>
      <description><![CDATA[<p>``Hello, im in need of help with my project using SRF10 ultrasonic sensor. Im and using arduino + processing for our project but our coding is not strong. I have 2 ultrasonic which use to track moving object. I need help in showing the object location and showing it change when the object changes location. I currently able to show a printed value but only for one sensor displayed on processing. Any kind soul able to help :)</p>

<p>Here is our processing code:</p>

<pre><code>import processing.serial.*;
//import cc.arduino.*;
//println(Arduino.list());
 String val;
Serial myPort;

float Distance1 = 0, Distance2 = 0;
float LocationX=0; // Assumed location of an object (X,Y)
float LocationY=0;
float SRF1_x=300;  // location of SRF1 (x,y)
float SRF1_y=100;
float SRF2_x=500;  // location of SRF2 (x,y)
float SRF2_y=100;
float AngularRes=PI/180*10; //   Angle change step size
int xPos = 1;      // horizontal position of the graph

void setup()
{
  size(1000, 700);
  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600); 
  background(200);
  smooth();
  myPort.bufferUntil('\n');
  DrawGrid();
}

void draw()
{
      if( myPort.available() &gt; 0) 
      {  // If data is available,
        val = myPort.readStringUntil('\n');  
      }
  println(val);
     FindLocation();
//     background(300, 300, 300);
     fill(300);
     ellipse(SRF1_x,SRF1_y,25,25); // location of SRF1
     fill(100);
     ellipse(SRF2_x,SRF2_y,25,25); // location of SRF2
     fill(400);
     ellipse(LocationX,LocationY,10,10); // actual location of an object


}

void serialEvent(Serial myPort)
{
  String str = myPort.readStringUntil('\n');
  if (str != null )
  {
      str = trim(str); //remove whitespace around our values
      float  DistanceArr[]=float (split(str, ','));
      Distance1= map( DistanceArr[0], 0, 540, 0, 3000); // map distance of SRF1 to another range
      Distance2= map( DistanceArr[1], 0, 540, 0, 3000); // map distance of SRF2 to another range
  }
}

void FindLocation(){
     float MinimumDist = 50000;
     float x_CL_SRF1, y_CL_SRF1, x_CL_SRF2, y_CL_SRF2,Cal_MinimumDist; // x-y coordinates along two circles
     for (float theta1 = 0; theta1 &lt; PI; theta1 = theta1+AngularRes) {
         x_CL_SRF1=SRF1_x +Distance1*cos(theta1);   // get x-y coordinates along circle for SRF1
         y_CL_SRF1=SRF1_y +Distance1*sin(theta1);
         ellipse(x_CL_SRF1,y_CL_SRF1,10,10);
         for (float theta2 = 0; theta2 &lt; PI; theta2 = theta2+AngularRes) {
              x_CL_SRF2=SRF2_x +Distance2*cos(theta2);  // get x-y coordinates along circle for SRF2
              y_CL_SRF2=SRF2_y +Distance2*sin(theta2);
              ellipse(x_CL_SRF2,y_CL_SRF2,10,10);
              Cal_MinimumDist=sqrt(sq(x_CL_SRF1- x_CL_SRF2)+sq(y_CL_SRF1- y_CL_SRF2));
              if (Cal_MinimumDist&lt;MinimumDist){
                  MinimumDist=Cal_MinimumDist;
                  LocationX=x_CL_SRF1;
                  LocationY=y_CL_SRF1;
               }

         }
    }     
}

void DrawGrid() {
    for (int i = 0; i &lt; 700; i = i+100) {
        line(0, i, 990, i);
        }

        for (int i = 0; i &lt; 1000; i = i+100) {
             line(i, 0, i, 690 );
        }
}
</code></pre>

<p>Here is the arduino code:
    /*
     *
     * rosserial srf02 Ultrasonic Ranger Example
     *
     * This example is calibrated for the srf02 Ultrasonic Ranger.
     *
     * By Poh Hou Shun 24 September 2015
    */</p>

<pre><code>//#include &lt;Sonar_srf02.h&gt; //srf02 specific library
#include &lt;Wire.h&gt;
//#include &lt;ros.h&gt;
//#include &lt;std_msgs/Float32.h&gt;


//Set up the ros node and publisher
//std_msgs::Float32 sonar_msg;
//ros::Publisher pub_sonar("sonar", &amp;sonar_msg);
//ros::NodeHandle nh;

//Sonar_srf02 MySonar; //create MySonar object

#define COMMANDREGISTER 0x00
#define RESULTREGISTER  0x02

#define CENTIMETERS 0x51
// use 0x50 for inches
// use 0x51 for centimeters
// use 0x52 for ping microseconds

#define NO_OF_SENSORS 2

int SEQUENCE[] = {115, 116};

int reading = 0;
String stringData;

void setup()
{

  Wire.begin();                // join i2c bus (address optional for master)
  Serial.begin(9600);          // start serial communication at 9600bps

  //nh.initNode();
  //nh.advertise(pub_sonar);

}


long publisher_timer;

void loop()
{

  if (millis() &gt; publisher_timer || 1) {

    for (int i = 0; i &lt; NO_OF_SENSORS; i++) {
      takeData(SEQUENCE[i]);
    }

    // step 2: wait for readings to happen
    delay(70);                   // datasheet suggests at least 65 milliseconds

    readData(SEQUENCE[0]);

    stringData = String(reading);
    Serial.print(reading);

    for (int i = 1; i &lt; NO_OF_SENSORS; i++) {
      readData(SEQUENCE[i]);
      stringData = ' ' + String(reading);
      Serial.print(' ');
      Serial.print(reading);    
    }

    //stringData = stringData + '\0';

    //sonar_msg.data = stringData;
    //pub_sonar.publish(&amp;sonar_msg);

    publisher_timer = millis() + 4000; //publish once a second
    //Serial.println(sensorReading);
    Serial.println('\0');

  }

  //Serial.println(stringData);   // print the reading
  //nh.spinOnce();

}

void takeData(int address) {

  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(address); // transmit to device #112 (0x70)

  // the address specified in the datasheet is 224 (0xE0)
  // but i2c adressing uses the high 7 bits so it's 112
  Wire.write(byte(COMMANDREGISTER));      // sets register pointer to the command register (0x00)
  Wire.write(byte(CENTIMETERS));      // command sensor to measure in "centimeters" (0x51)

  Wire.endTransmission();      // stop transmitting

}

void readData(int address) {

  // step 3: instruct sensor to return a particular echo reading
  Wire.beginTransmission(address); // transmit to device #112
  Wire.write(byte(RESULTREGISTER));      // sets register pointer to echo #1 register (0x02)
  Wire.endTransmission();      // stop transmitting

  // step 4: request reading from sensor
  Wire.requestFrom(address, 2);    // request 2 bytes from slave device #112

  // step 5: receive reading from sensor
  if (2 &lt;= Wire.available()) { // if two bytes were received
    reading = Wire.read();  // receive high byte (overwrites previous reading)
    reading = reading &lt;&lt; 8;    // shift high byte to be high 8 bits
    reading |= Wire.read(); // receive low byte as lower 8 bits
  }

  delay(250);
  //Serial.println(reading);

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>EGLDisplayUtil error – Processing on Raspberry</title>
      <link>https://forum.processing.org/two/discussion/18530/egldisplayutil-error-processing-on-raspberry</link>
      <pubDate>Thu, 13 Oct 2016 14:03:45 +0000</pubDate>
      <dc:creator>lxnr_p</dc:creator>
      <guid isPermaLink="false">18530@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone,</p>

<p>I'm working on a raspberry and when I run it, I everytime have this error in the console: (but the sketch run even though)</p>

<pre><code>EGLDisplayUtil.EGLDisplays: Shutdown (open: 1)
EGLDisplayUtil: Open EGL Display Connections: 1
EGLDisplayUtil: Open[0]: 0x1: EGLDisplayRef[0x1: refCnt 2]
</code></pre>

<p>Do you know what does it mean and how I can solve it?
The sketch read the values of the arduino (plugged on the raspberry)  where a proximity sensor is plugged and when we put an object above the sensor the first video change and another one is launched.
I also have another problem: When the sketch is running, the videos are slow down. And I remove everything that relate to the arduino and the sensor in processing, the videos are fine.</p>

<p>So is somebody can help me for this, it drives me crazy, and I didn't found a thing on our friend Google...
Thanks so much :)</p>

<p>Here my code:</p>

<pre><code>    ////////////////////////////////////////////
    ////////////////////////////////// LIBRARIES
    ////////////////////////////////////////////

    import processing.serial.*;
    import processing.video.*;





    /////////////////////////////////////////////////
    ////////////////////////////////// INITIALIZATION
    /////////////////////////////////////////////////

    Movie mymovie;
    Movie mymovie2;





    ////////////////////////////////////////////
    ////////////////////////////////// VARIABLES
    ////////////////////////////////////////////

    int lf = 10;    // Linefeed in ASCII
    String myString = null;
    Serial myPort;  // The serial port
    int sensorValue = 0; //value of the sensore
    int x = 100; //the sensor will be triggered when this value is reached. Modify it to change when the videos will switch




    /////////////////////////////////////////////
    ////////////////////////////////// VOID SETUP
    /////////////////////////////////////////////

    void setup() {
      //frameRate(50);
      fullScreen();
      //size(1280, 1024, P3D);
      // List all the available serial ports
      printArray(Serial.list());
      // Open the port you are using at the rate you want:
      myPort = new Serial(this, Serial.list()[1], 9600);
      myPort.clear();
      // Throw out the first reading, in case we started reading 
      // in the middle of a string from the sender.
      myString = myPort.readStringUntil(lf);
      myString = null;
      //load the video
      mymovie = new Movie(this, "VIDEO_1_v06bis.mov"); //Modify the line in quotation marks to change the videos. (put it inside the "data" folder
      mymovie2 = new Movie(this, "VIDEO_2_v02.mov");
      //set the videos for a continuous loop
      mymovie.loop();
      mymovie2.loop();
    }




    ////////////////////////////////////////////
    ////////////////////////////////// VOID DRAW
    ////////////////////////////////////////////

    void draw() {
      //image(mymovie, 0, 0); //display the video in a continuous loop
      // to trigger the sensor
      // check if there is something new on the serial port
      while (myPort.available() &gt; 0) {
        // store the data in myString 
        myString = myPort.readStringUntil(lf);
        // check if we really have something
        if (myString != null) {
          myString = myString.trim(); // let's remove whitespace characters
          // if we have at least one character...
          if (myString.length() &gt; 0) {
            println(myString); // print out the data we just received
            // if we received a number (e.g. 123) store it in sensorValue, we sill use this to change the background color. 
            try {
              sensorValue = Integer.parseInt(myString);
            } 
            catch(Exception e) {
            }
          }
        }
      }


      ///////////SENSOR TRIGGERED
      ///////////////////////////

      if (x &lt; sensorValue) {
        mymovie.jump(0);
        //background(mymovie2);
        image(mymovie2, mouseX, mouseY);
        //mymovie2.pause();
      } else {
        //mymovie2.play();
        //mymovie.jump(0);
      }


      ///////////SENSOR NOT TRIGGERED
      ///////////////////////////////

      if (x &gt; sensorValue) {
        mymovie2.jump(0);
        //background(mymovie);
        image(mymovie, mouseX, mouseY);
        //mymovie.pause();
      } else {
        //mymovie.play();
      }
    }



    //////////////////////////////////////////////
    ////////////////////////////////// VOID CUSTOM
    //////////////////////////////////////////////

    void movieEvent(Movie mymovie) {
      mymovie.read(); //read the video
      mymovie2.read();
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Data received from Arduino to Processing, but is not saved in file</title>
      <link>https://forum.processing.org/two/discussion/18129/data-received-from-arduino-to-processing-but-is-not-saved-in-file</link>
      <pubDate>Sat, 10 Sep 2016 11:17:29 +0000</pubDate>
      <dc:creator>JRob</dc:creator>
      <guid isPermaLink="false">18129@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody</p>

<p>I'm currently trying to send some data from Arduino to Processing, so I can save it in a file.
To be more specific, there are two variables (frequency of a blinking LED and respective LED number) which should be saved in tabular form.</p>

<p>Hereby the following Processing code is used:</p>

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


Serial myPort;
Table dataTable; //table to store my values.

int lf = 10;
String Arduinostring = null;
float values;

String fileName;
void setup()
{
  String portName = Serial.list()[0]; 
  myPort = new Serial(this, portName, 9600); //the port I'm using to listen to the serial port

  dataTable = new Table();
  dataTable.addColumn("id"); 


  //columns for values
  dataTable.addColumn("Data");
}

  void draw() {
    while (myPort.available() &gt; 0) {
      Arduinostring = myPort.readStringUntil(lf);
      if (Arduinostring != null) {
          print(Arduinostring);  // Prints String
          values=float(Arduinostring);  // Converts and prints float
          println(values);
      }
    TableRow newRow = dataTable.addRow(); //add a row for this new reading
    newRow.setInt("id", dataTable.lastRowIndex());//record a unique identifier (the row's index)

    //record information. 
    newRow.setFloat("Data", values);   
    }

    saveTable(dataTable, "data/new.csv"); // save it to computer.

}
</code></pre>

<p>My intention here is to get my data into the table (and into my file).
I managed to receive the required data (frequency, LED number), but this data isn't saved in my file.
The mentioned file is created by the way and at least has the right ID for each Row.</p>

<p>What I simply do not understand is that he can't save it though the received data should be converted to float with the command num=float(myString), shouldn't it?</p>

<p>Many thanks in advance for any help!</p>
]]></description>
   </item>
   <item>
      <title>sending data from arduino to processing</title>
      <link>https://forum.processing.org/two/discussion/17981/sending-data-from-arduino-to-processing</link>
      <pubDate>Fri, 26 Aug 2016 20:10:33 +0000</pubDate>
      <dc:creator>afroginacup</dc:creator>
      <guid isPermaLink="false">17981@/two/discussions</guid>
      <description><![CDATA[<p>Hi I am working on my arduino project and am trying to send ultrasonic sensor data and pulse sensor data to processing.
I've already put sound file to processing but I want the "heartbeat.mp3" file to be played whenever pulse is detected. I tried putting 'QS == true' and other ways like that, but I still have not figured out.</p>

<p>Also once I get the sound file play according to the pulse I would like to control the volume of it with data received by ultrasonic sensors. Like getting louder when the distance gets closer.</p>

<p>I'm a total beginner and just so confused how I should put code for both programs. Help me and thanks!</p>

<p>My arduino code :</p>

<p>//  Variables
int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13;                // pin to blink led at each beat
int fadePin = 5;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 0;                 // used to fade LED on with PWM on fadePin</p>

<p>// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat". 
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.</p>

<p>// Regards Serial OutPut
static boolean serialVisual = false;   // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse</p>

<h1>define trigPin1 12</h1>

<h1>define echoPin1 11</h1>

<h1>define trigPin2 3</h1>

<h1>define echoPin2 2</h1>

<p>long duration, distance, RightSensor, LeftSensor;</p>

<p>void setup(){
  pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
  pinMode(fadePin,OUTPUT);          // pin that will fade to your heartbeat!
  Serial.begin(115200);             // we agree to talk fast!
  interruptSetup();</p>

<p>Serial.begin (9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);</p>

<p>void loop(){</p>

<pre><code>serialOutput() ;       
</code></pre>

<p>if (QS == true){     // A Heartbeat Was Found
                       // BPM and IBI have been Determined
                       // Quantified Self "QS" true when arduino finds a heartbeat
        fadeRate = 255;         // Makes the LED Fade Effect Happen
                                // Set 'fadeRate' Variable to 255 to fade LED with pulse
        serialOutputWhenBeatHappens();   // A Beat Happened, Output that to serial.<br />
        QS = false;                      // reset the Quantified Self flag for next time<br />
  }</p>

<p>ledFadeToBeat();                      // Makes the LED Fade Effect Happen 
  delay(20);                             //  take a break</p>

<p>SonarSensor(trigPin1, echoPin1);
RightSensor = distance;
SonarSensor(trigPin2, echoPin2);
LeftSensor = distance;</p>

<p>Serial.print(LeftSensor);
Serial.print(" - ");
Serial.print(RightSensor);
Serial.print(" - ");</p>

<p>}</p>

<p>void SonarSensor(int trigPin,int echoPin)
{ 
  digitalWrite(trigPin, LOW);
  delayMicroseconds(500);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
}</p>

<p>void ledFadeToBeat(){
    fadeRate -= 15;                         //  set LED fade value
    fadeRate = constrain(fadeRate,0,255);   //  keep LED fade value from going into negative numbers!
    analogWrite(fadePin,fadeRate);          //  fade LED
  }</p>

<p>+++</p>

<p>My processing code :</p>

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

<p>Serial myPort;</p>

<p>SoundFile file;</p>

<p>int number_of_swallowed;
int Sensor;      // HOLDS PULSE SENSOR DATA FROM ARDUINO
int IBI;         // HOLDS TIME BETWEN HEARTBEATS FROM ARDUINO
int BPM;         // HOLDS HEART RATE VALUE FROM ARDUINO necessary?</p>

<p>int trigPin1;
int echoPin1;
int trigPin2;
int echoPin2;</p>

<p>int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13;                // pin to blink led at each beat
int fadePin = 5;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 0;                 // used to fade LED on with PWM on fadePin
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat". 
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.</p>

<p>boolean beat = false;    // set when a heart beat is detected, then cleared when the BPM graph is advanced</p>

<p>// SERIAL PORT STUFF TO HELP YOU FIND THE CORRECT SERIAL PORT</p>

<p>/*
String serialPort;
 String[] serialPorts = new String[Serial.list().length];
 boolean serialPortFound = false;
 */</p>

<p>void setup() {
  size(400, 200);</p>

<p>myPort = new Serial(this, "COM6", 9600);
  myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line
  //myPort = new Serial(this, "COM6", 9600);//
  //myPort.buffer(1);//?</p>

<p>// Load a soundfile from the /data folder of the sketch and play it back
  file = new SoundFile(this, "whalesound.mp3");
  file.play();</p>

<p>if (QS == true);
  {
    file = new SoundFile(this, "heartbeat.mp3");
    file.play();
  }
}</p>

<p>void draw()
{
  background(0);
  textSize(50);
  text(number_of_swallowed +" swallowed", 50, 100);
}</p>

<p>void mouseReleased() {
  if (mouseButton == LEFT) { 
    number_of_swallowed++;
  } else { 
    number_of_swallowed = 0;
  }
}</p>
]]></description>
   </item>
   <item>
      <title>Out of Control y Axis- ROLLING GRAPH</title>
      <link>https://forum.processing.org/two/discussion/17900/out-of-control-y-axis-rolling-graph</link>
      <pubDate>Fri, 19 Aug 2016 03:53:51 +0000</pubDate>
      <dc:creator>Chil_Polins</dc:creator>
      <guid isPermaLink="false">17900@/two/discussions</guid>
      <description><![CDATA[<p>Noobie here, I'm trying to take an input from an arduino over a usb and plot onto a graph. Everything is fine except I cant seem to map where the y begins and ends on my graph. I tried so many things but its stuck between 0 and about 400px. You'll see the box where the graph is suppose to occupy. I can't move/control the y axis. I drew out the issue in red on the attached image, please help!!</p>

<p>You'll see reference to multiple sensors, I am only trying to plot the sensor "moisture" for now.</p>

<pre><code>/This sketch is frankensteined from the SerialCall Response example with arduino and 
//this guy's sketch(code in description of video) - <a href="http://pastebin.com/kSrU3nVH" target="_blank" rel="nofollow">http://pastebin.com/kSrU3nVH</a>

import processing.serial.*;

int moisture;  //the only sensor I'm currently trying to plot 
float inByte;
int second; //sensors that ar![]()e not yet plotted but printed in the Console
int third;  // " "
int fourth; // " "

Serial myPort;                       // The serial port
int[] serialInArray = new int[4];    // Where we'll put what we receive
int serialCount = 0;                 // A count of how many bytes we receive
PFont  g_font;
boolean firstContact = false;        // Whether we've heard from the microcontroller

int[] yValues;
int w;

//SETUP
void setup() {
  size(1280, 720);  // Stage size

  g_font = loadFont("ArialMT-20.vlw");
  textFont(g_font, 20);

  w = 640; //width of our plot
  strokeWeight(1);
  smooth(); // or noSmooth();
  yValues = new int[w];

  println(Serial.list());
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);
}

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

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

    moisture = int(map(inByte, 0, 255, 360, 25));
    //setting the boundry for the graph line, inside box EXCEPT IT DOESNT WORK
  }

  //This should be down here, but works inside the if statement.
  //moisture = int(map(inByte, 0, 255, 360, 25));

  //Background and box for graph
  background(55);
  rect(25, 25, 615, 335);
  fill(255);
  //LEGEND
  strokeWeight(1.5);
  stroke(255, 0, 0);     
  line(20, 420, 35, 420);
  stroke(0, 255, 0);     
  line(20, 440, 35, 440);
  stroke(0, 0, 255);     
  line(20, 460, 35, 460);
  stroke(255, 255, 0);   
  line(20, 480, 35, 480);

  fill(0, 0, 0);
  text("Moisture", 40, 430);
  text("Analog A1", 40, 450);
  text("Analog A2", 40, 470);
  text("Analog A3", 40, 490);

  //ACTUAL PLOTTED LINE
  for (int i = 1; i &lt; w; i++) {
    yValues[i-1] = yValues[i];
  }
  yValues[w-1] = moisture; 
  //}

  stroke(120, 200, 0);
  line(w, moisture, 0, moisture);
  strokeWeight(3);


  //This controls the horizontal "TICKER LINE"
  for (int i=1; i&lt;w; i++) {
    //stroke (rgb)
    stroke(220, 75, yValues[i]);
    //point folar x, float y
    point(i, yValues[i]);
    rect(0, 25, 50, 335);
    fill(255);
  }
}

void serialEvent(Serial myPort) {
  // read a byte from the serial port:
  int inByte = myPort.read();

  if (firstContact == false) {
    if (inByte == 'A') {
      myPort.clear();          // clear the serial port buffer
      firstContact = true;     // you've had first contact from the microcontroller
      myPort.write('A');       // ask for more
    }
  } else {
    // Add the latest byte from the serial port to array:
    serialInArray[serialCount] = inByte;
    serialCount++;

    // If we have 3 bytes:
    if (serialCount &gt; 3) {
      moisture = serialInArray[0];
      second = serialInArray[1];
      third = serialInArray[2];
      fourth = serialInArray[3];

      // print the values (for debugging purposes only):
      println(moisture + "\t" + second + "\t" + third + "\t" + fourth);

      // Send a capital A to request new sensor readings:
      myPort.write('A');
      // Reset serialCount:
      serialCount = 0;
    }
  }
}

/*ARDUINO UNO CODE
 int firstSensor = 0;    // first analog sensor
 int secondSensor = 0;   // second analog sensor
 int thirdSensor = 0;    // digital sensor
 int fourthSensor = 0; //turning this into a fluxuating value
 int inByte = 0;         // incoming serial byte

 void setup()
 {
 // start serial port at 9600 bps:
 Serial.begin(9600);


 pinMode(2, INPUT);   // digital sensor is on digital pin 2
 establishContact();  // send a byte to establish contact until receiver responds
 }

 void loop()

 {

 // if we get a valid byte, read analog ins:
 if (Serial.available() &gt; 0) {
 // get incoming byte:
 inByte = Serial.read();
 // read first analog input, divide by 4 to make the range 0-255:
 firstSensor = analogRead(A0);
 // delay 10ms to let the ADC recover:
 delay(10);
 // read second analog input, divide by 4 to make the range 0-255:
 secondSensor = analogRead(A1) / 4;
 // read  switch, map it to 0 or 255L
 thirdSensor = map(digitalRead(A2), 0, 1, 0, 255);
 // send sensor values:
 fourthSensor = analogRead(A3) / 4; //new sensor I added
 Serial.write(firstSensor);
 Serial.write(secondSensor);
 Serial.write(thirdSensor);
 Serial.write(fourthSensor);

 }
 }

 void establishContact() {
 while (Serial.available() &lt;= 0) {
 Serial.print('A');   // send a capital A
 delay(300);

 }
 }
 */![Screen Shot 2016-08-18 at 11.45.51 PM](<a href="https://forum.processing.org/two/uploads/imageupload/608/2KIEZIROU05C.jpg" target="_blank" rel="nofollow">https://forum.processing.org/two/uploads/imageupload/608/2KIEZIROU05C.jpg</a> "Screen Shot 2016-08-18 at 11.45.51 PM")
</code></pre>
]]></description>
   </item>
   <item>
      <title>processing arduino 2 sensors ultrasonic</title>
      <link>https://forum.processing.org/two/discussion/17846/processing-arduino-2-sensors-ultrasonic</link>
      <pubDate>Mon, 15 Aug 2016 03:06:23 +0000</pubDate>
      <dc:creator>felipera</dc:creator>
      <guid isPermaLink="false">17846@/two/discussions</guid>
      <description><![CDATA[<p>Hello
Get accurate processing via 2 Separated Values ​​2 ultrasonic distance sensors via Arduino .
In arduino I'm OS Values ​​tendon however no processing I'm picking up .
Can anyone help , follow OS 2 codes
thanks in advance</p>

<p>ARDUINO</p>

<h1>include &lt;Ultrasonic.h&gt;</h1>

<h1>define echoPin 13 //Pino 13 recebe o pulso do echo</h1>

<h1>define trigPin 12 //Pino 12 envia o pulso para gerar o echo</h1>

<h1>define echoPin2 4 //Pino 4 recebe o pulso do echo</h1>

<h1>define trigPin2 5 //Pino 5 envia o pulso para gerar o echo</h1>

<p>//iniciando a função e passando os pinos
Ultrasonic ultrasonic(12,13);
Ultrasonic ultrasonic2(4,5);</p>

<p>void setup()
{
   Serial.begin(9600); //inicia a porta serial
   pinMode(echoPin, INPUT); // define o pino 13 como entrada (recebe)
   pinMode(trigPin, OUTPUT); // define o pino 12 como saida (envia)
   pinMode(echoPin2, INPUT); // define o pino 4 como entrada (recebe)
   pinMode(trigPin2, OUTPUT); // define o pino 5 como saida (envia)
}</p>

<p>void loop()
{
  //seta o pino 12 com um pulso baixo "LOW" ou desligado ou ainda 0
    digitalWrite(trigPin, LOW);
  // delay de 2 microssegundos
    delayMicroseconds(2);
  //seta o pino 12 com pulso alto "HIGH" ou ligado ou ainda 1
    digitalWrite(trigPin, HIGH);
  //delay de 10 microssegundos
    delayMicroseconds(10);
  //seta o pino 12 com pulso baixo novamente
    digitalWrite(trigPin, LOW);
  // função Ranging, faz a conversão do tempo de
  //resposta do echo em centimetros, e armazena
  //na variavel distancia
    float duration = pulseIn(echoPin,HIGH);<br />
  //Esse calculo é baseado em s = v . t, lembrando que o tempo vem dobrado<br />
  //porque é o tempo de ida e volta do ultrassom<br />
    float distancia = duration /29 / 2 ; 
     //seta o pino 12 com um pulso baixo "LOW" ou desligado ou ainda 0
    digitalWrite(trigPin2, LOW);
  // delay de 2 microssegundos
    delayMicroseconds(2);
  //seta o pino 5 com pulso alto "HIGH" ou ligado ou ainda 1
    digitalWrite(trigPin2, HIGH);
  //delay de 10 microssegundos
    delayMicroseconds(10);
  //seta o pino 5 com pulso baixo novamente
    digitalWrite(trigPin2, LOW);
  // função Ranging, faz a conversão do tempo de
  //resposta do echo em centimetros, e armazena
  //na variavel distancia
    float duration2 = pulseIn(echoPin2,HIGH);<br />
  //Esse calculo é baseado em s = v . t, lembrando que o tempo vem dobrado<br />
  //porque é o tempo de ida e volta do ultrassom<br />
    float distancia2 = duration2 /29 / 2 ;</p>

<p>Serial.println("pé da frente");
Serial.println(distancia);
Serial.println("pé de tras");
Serial.println(distancia2);
delay(1000); //espera 1 segundo para fazer a leitura novamente
}</p>

<p>PROCESSING</p>

<p>// Example by Tom Igoe</p>

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

<p>Serial myPort;    // The serial port
PFont myFont;     // The display font
String distancia;
String distancia2;// Input string from serial port
int lf = 10;
;      // ASCII linefeed</p>

<p>void setup() { 
  size(500,500); 
  // You'll need to make this font with the Create Font Tool 
  //myFont = loadFont("ArialMS-18.vlw"); 
  //textFont(myFont, 18); 
  // List all the available serial ports: 
  printArray(Serial.list());</p>

<p>myPort = new Serial(this, Serial.list()[0], 9600); 
  myPort.bufferUntil(lf); 
}</p>

<p>void draw() { 
  background(0); 
  text("Pé de trás: " + distancia, 10,50); 
  text("Pé de trás: " + distancia2, 10,150);</p>

<p>}</p>

<p>void serialEvent(Serial p) { 
distancia = p.readString(); 
}</p>
]]></description>
   </item>
   <item>
      <title>Need some form of debounce for my code and have no idea how to implement one</title>
      <link>https://forum.processing.org/two/discussion/17694/need-some-form-of-debounce-for-my-code-and-have-no-idea-how-to-implement-one</link>
      <pubDate>Fri, 29 Jul 2016 11:13:55 +0000</pubDate>
      <dc:creator>silageman</dc:creator>
      <guid isPermaLink="false">17694@/two/discussions</guid>
      <description><![CDATA[<p>As above i'm currently working on an arduino project (physical edrum trigger/piezo) i currently have an uno talking to processing 3 through a serial connection and then displaying a simple graph, when the inByte is greater than 1 (pull down resistor is at 0 untriggered) it sends midi notes to ezdrummer 2, i have all this working my problem is when i hit the drum it triggers multiple times within a short period of the strike, anyone know what would be the best solution for a debounce?</p>

<p>my current code below.</p>

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

import themidibus.*; 

MidiBus myBus; 

Serial myPort;        
int xPos = 1;         
float inByte = 0;

void setup () {
  MidiBus.list();
  // set the window size:
  size(900, 400);

  println(Serial.list());
  myBus = new MidiBus(this, 1, 3); 

  myPort = new Serial(this, Serial.list()[1], 115200);

  myPort.bufferUntil('\n');

  background(0);
}

void draw () {
  // draw the line:
  stroke(127, 34, 255);
  line(xPos, height, xPos, height - inByte);

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

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

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

    println(inByte);
    int a = 56;
    inByte = map(inByte, 0, 1023, 0, 127);
    int test = int(inByte);
    if(inByte &gt; 2){
      myBus.sendNoteOn(1, 38, test); // Send a Midi noteOn
      delay(1);
      inByte--;
      myBus.sendNoteOff(1, 38, test); // Send a Midi nodeOff
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>LUBUNTU error opening serial port /dev/ttyS0: Incorrect serial port</title>
      <link>https://forum.processing.org/two/discussion/17512/lubuntu-error-opening-serial-port-dev-ttys0-incorrect-serial-port</link>
      <pubDate>Wed, 13 Jul 2016 12:49:14 +0000</pubDate>
      <dc:creator>ilioSS</dc:creator>
      <guid isPermaLink="false">17512@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>I just installed LUBUNTU 16-04 with a running arduino IDE. No problem.</p>

<p>Now I would like to install processing3. I have it running.</p>

<p>But my adxl345 read out in pitch-roll give the above mentioned error.</p>

<p>Already looked on the internet for possible solutions s.a. i must be mention of the group etc.</p>

<p>Al I treid nothing works.</p>

<p>Situation arduino for linux and processing3</p>

<p>linux prog is LUBUNTU 16-04 and linux32 4.4.0.22</p>

<p>Who has the solution. Help is very much apriciated.</p>

<p>Kind regards,</p>

<p>ilioSS</p>

<p>btw arduino uses ttyUSB0  serial port</p>
]]></description>
   </item>
   <item>
      <title>How ti invert grayscale (0-255) in this code ?</title>
      <link>https://forum.processing.org/two/discussion/17497/how-ti-invert-grayscale-0-255-in-this-code</link>
      <pubDate>Tue, 12 Jul 2016 11:50:03 +0000</pubDate>
      <dc:creator>Josip</dc:creator>
      <guid isPermaLink="false">17497@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone ! I have a LIDAR lite v2 and i used it to measure distances , i mount him on 2 servo motors wich rotates in Y and X and lidar scanning distance in that time. Now i have this program which communicate with arduino and creating point cloud from degrees of X servo degrees of Y servo and distances in cm .</p>

<p>Now the question is why a get small picture whatever i put in size() i get the same small picture and with this program DARKER the pixel is closer the object is. AND NOW the main question is how to invert grayscale , cause i want darker pixel farther.</p>

<p>Sorry for so many words and thank u.</p>

<p>This is the code in processing.</p>

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

float pcolor = 0; // point color value
float xVal = 0;  // x value
float yVal = 0;  // y value

Serial myPort;

void setup() {

  size(400,200);

  printArray(Serial.list()); 

  myPort = new Serial(this, Serial.list()[0], 57600);

  myPort.bufferUntil('\n');   
  background(0);
}

void draw() {
  stroke(pcolor);    
  point(xVal,yVal);
}

void serialEvent(Serial myPort) {

  String inString = myPort.readStringUntil('\n');  

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

    float[] colors = float(split(inString, ","));    

    if (colors.length &gt;=3) {       
      xVal = colors[0];          
      yVal = colors[1];
      pcolor = map(colors[2], 0, 400, 0,255);
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to save ellipse color if mouse pressed via serial Port</title>
      <link>https://forum.processing.org/two/discussion/17039/how-to-save-ellipse-color-if-mouse-pressed-via-serial-port</link>
      <pubDate>Wed, 08 Jun 2016 11:39:34 +0000</pubDate>
      <dc:creator>Tipikosh</dc:creator>
      <guid isPermaLink="false">17039@/two/discussions</guid>
      <description><![CDATA[<p>Hey, i want the ellipse that is being drawn to save its color on every position it was. i want to have the pen Function in Paint.
here is my code and thanks for your help!!</p>

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

<p>float x,y;</p>

<p>void setup() {</p>

<p>size(800,800);</p>

<p>Serial arduino = new Serial(this, "COM3", 250000);</p>

<p>arduino.bufferUntil('\n');</p>

<p>}</p>

<p>void draw()</p>

<p>{</p>

<p>}</p>

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

<p>String rawString = p.readStringUntil('\n');</p>

<p>if (rawString != null) {</p>

<p>rawString = rawString.trim();</p>

<p>try{</p>

<pre><code>String[] values = split(rawString,",");

int serialX = int(values[0]);

int serialY = int(values[1]);    

x = map(serialY,0,640,0,width);

y = map(serialX,0,480,0,height);
</code></pre>

<p>/* maybe something like</p>

<p>if (values[0]!=0)</p>

<p>{</p>

<p>fill
ellipse(x,y,10,10);
}</p>

<p>*/</p>

<p>}catch(Exception e){</p>

<pre><code>println("Error parsing string from Serial:");

e.printStackTrace();
</code></pre>

<p>}</p>

<p>}</p>

<p>}</p>

<p>`</p>
]]></description>
   </item>
   <item>
      <title>Two Bluetooth Arduino Input - Possible?</title>
      <link>https://forum.processing.org/two/discussion/16988/two-bluetooth-arduino-input-possible</link>
      <pubDate>Sat, 04 Jun 2016 13:50:29 +0000</pubDate>
      <dc:creator>CharlesDesign</dc:creator>
      <guid isPermaLink="false">16988@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>I'm looking to have a total of 32 force sensors values being sent via Bluetooth from two separate Arduino's to my processing sketch.</p>

<p>Is this possible?
Can I have two Bluetooth connections receiving data simultaneously?</p>

<p>Thanks in advance,
Charles</p>
]]></description>
   </item>
   </channel>
</rss>