<?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 serialevent() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/p2/feed.rss?Tag=serialevent%28%29</link>
      <pubDate>Sun, 08 Aug 2021 15:17:17 +0000</pubDate>
         <description>Tagged with serialevent() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedserialevent%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <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>CharAt command does not exist</title>
      <link>https://forum.processing.org/two/discussion/22997/charat-command-does-not-exist</link>
      <pubDate>Fri, 09 Jun 2017 12:56:53 +0000</pubDate>
      <dc:creator>tubbo</dc:creator>
      <guid isPermaLink="false">22997@/two/discussions</guid>
      <description><![CDATA[<p>Hi everybody,
I need help, the command charAt() does not work because does not exist. How can I fix It?
PLZ i need help.</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/858/LTDR6LN1NKRA.PNG" alt="Capture" title="Capture" /></p>
]]></description>
   </item>
   <item>
      <title>Serial Communication.</title>
      <link>https://forum.processing.org/two/discussion/22971/serial-communication</link>
      <pubDate>Wed, 07 Jun 2017 08:13:56 +0000</pubDate>
      <dc:creator>Noerrenebels</dc:creator>
      <guid isPermaLink="false">22971@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
the following Code:</p>

<p><code>void serialEvent(Serial p) {
  message = myPort.readStringUntil(124);
  if (message != null) {
    int messageLength = message.length();
    message = message.substring(0, messageLength - 1);
    println(message);
    try {
      elements = split(message, ":");
      println(elements[0]+"????");
      println(elements[0].equals("Panel"));
      if (elements[0].equals("Panel") == true) {
        panel = int (elements[1]);
        println("Panel = " + str(panel));
      }
    }
    catch (Exception e) {
    }
  }
}</code></p>

<p>Print out to Console:</p>

<hr />

<p>`Panel:1
Panel????
true
Panel = 1</p>

<p>Panel:2</p>

<p>Panel????
false</p>

<h2>`</h2>

<p>Why the second time 'elements[0].equals("Panel")' is false?</p>

<p>Sincerly
Jörg</p>
]]></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>[ControlP5 + Serial] Serial input to textfield controller</title>
      <link>https://forum.processing.org/two/discussion/22224/controlp5-serial-serial-input-to-textfield-controller</link>
      <pubDate>Wed, 26 Apr 2017 13:50:03 +0000</pubDate>
      <dc:creator>Blad2021</dc:creator>
      <guid isPermaLink="false">22224@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>So going to do my best to describe this, it might sound a bit more complicated then intended.  I'm trying to set the value of a textfield controller (using ControlP5 library) with input from the Serial.  I could do this now by using a bunch of if statements but thats not very attractive therefore I want a function.  I have everything setup on my serial to ouput the following:</p>

<p>SEN.x.y</p>

<p>"SEN" being what it reads for to determine the function.<br />
(x) - The textfield ID to change
(y) - The value to change the textfield to.</p>

<p>My code so far:</p>

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

Serial myPort;  // Create object from Serial class**
String inByte;**
String s;**
ControlP5 cp5;
String temp;
String endchar = "\n";
Textarea consoletext;
Textfield Timer1;
Println console;
//Variables
boolean firstContact = false;
boolean globalState [] = {false, false, false, false, false, false, false, false};
int pin [] = {22, 24, 26, 28, 30, 32, 34, 36};

void setup() 
{  
  size(800,500);
  cp5 = new ControlP5(this);
  cp5.enableShortcuts();

  cp5.addTextfield("console")
    .setSize(360,35)
    .setCaptionLabel("Console Injection Module")
    .setPosition(20,430)
    .setFont(createFont("arial",14))
    .setAutoClear(true)
    ;

  cp5.addTextfield("Timer1")
    .setId(1)
    .setPosition(20,70)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(true)
    .setCaptionLabel("EEPROM: Timer 1")
    ;
  cp5.addTextfield("Timer2")
    .setId(2)
    .setPosition(20,130)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(true)
    .setCaptionLabel("EEPROM: Timer 2")
    ;
  cp5.addTextfield("Timer3")
    .setId(3)
    .setPosition(20,190)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(true)
    .setCaptionLabel("EEPROM: Timer 3")
    ;
  cp5.addTextfield("Timer4")
    .setId(4)
    .setPosition(20,250)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(false)
    .setCaptionLabel("EEPROM: Timer 4")
    ;
  cp5.addTextfield("Timer5")
    .setId(5)
    .setPosition(20,310)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(false)
    .setCaptionLabel("EEPROM: Timer 5")
    ;
  cp5.addTextfield("Timer6")
    .setId(6)
    .setPosition(20,370)
    .setSize(200,35)
    .setFont(createFont("arial",12))
    .setAutoClear(false)
    .setCaptionLabel("EEPROM: Timer 6")
    ;
  cp5.addButton("button1")
    .setSize(60,20)
    .setCaptionLabel("LED On")
    .setPosition(235,70)
    ;
  cp5.addButton("button2")
    .setSize(60,20)
    .setCaptionLabel("LED Off")
    .setPosition(235,100)
    ;
  cp5.addButton("button4")
    .setSize(60,20)
    .setCaptionLabel("Relays On")
    .setPosition(235,130)
    ;
  cp5.addButton("button3")
    .setSize(60,20)
    .setCaptionLabel("Relays Off")
    .setPosition(235,160)
    ;
  cp5.addBang("Relay1")
     .setPosition(310,50)
     .setId(1)
     .setSize(60,30)
     .setCaptionLabel("relay1")
     ;

  cp5.addBang("Relay2")
     .setPosition(310,95)
     .setSize(60,30)
     .setId(2)
     .setCaptionLabel("Relay 2")
     ;

  cp5.addBang("Relay3")
     .setPosition(310,140)
     .setSize(60,30)
     .setId(3)
     .setCaptionLabel("Relay 3")
     ;

  cp5.addBang("Relay4")
     .setPosition(310,185)
     .setSize(60,30)
     .setId(4)
     .setCaptionLabel("Relay 4")
     ;

  cp5.addBang("Relay5")
     .setPosition(310,230)
     .setSize(60,30)
     .setId(5)
     .setCaptionLabel("Relay 5")
     ;
  cp5.addBang("Relay6")
     .setPosition(310,275)
     .setSize(60,30)
     .setId(6)
     .setCaptionLabel("Relay 6")
     ;
  cp5.addBang("Relay7")
     .setPosition(310,320)
     .setSize(60,30)
     .setId(7)
     .setCaptionLabel("Relay 7")
     ;
  cp5.addBang("Relay8")
     .setPosition(310,365)
     .setSize(60,30)
     .setId(8)
     .setCaptionLabel("Relay 8")
     ;
consoletext = cp5.addTextarea("txt")
  .setPosition(440,20)
  .setSize(350, 465)
  .setFont(createFont("", 12))
  .setLineHeight(14)
  .setColor(color(255, 255, 255, 255))
  .setColorBackground(color(100, 100))
  .setColorForeground(color(255, 100));
  ;
  cp5.addTextlabel("ctext")
    .setText("Console")
    .setPosition(436,3)
    .setColorValue(255)
    .setFont(createFont("Arial",14));
  cp5.addTextlabel("stitle")
    .setText("Machine Serial")
    .setPosition(10,10)
    .setColorValue(color(200, 17, 0, 255))
    .setFont(createFont("Arial",24));
  cp5.addTextlabel("subtitle")
    .setText("Control Panel")
    .setPosition(30,35)
    .setColorValue(200)
    .setFont(createFont("Arial",16));

  console = cp5.addConsole(consoletext);


  //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, "COM3", 9600);
  myPort.bufferUntil('\n');

}

void draw() {
  background(0);
  fill(255);
  for (int i=0;i&lt;globalState.length;i++){
    if (globalState[i] == false){
      fill(color(200, 20, 0, 255));
      rect(385, 50+i*45, 30, 30);
    }
    else{
      fill(color(123, 255, 0, 255));
      rect(385, 50+i*45, 30, 30);
    }
  }
}
void controlEvent(ControlEvent test) {
  if(test.isAssignableFrom(Textfield.class)){
    if("console".equals(test.getName())){
      temp = test.getStringValue();
      if("LED On".equals(temp)){
        myPort.write("2");
        println("Sent: LED ON");
      }else if("LED Off".equals(temp)){
        myPort.write("1");
        println("Sent: LED OFF");
      }else if("help".equals(temp)){
        println("Help:");
        println("/  Commands:");
        println("/  - Update.x.y - Updates control pin layout.");
        println("     (x) - Array location  (y) - PIN");
        println("    Starts at 0!");
        println("/  - EEPROM.x.y - Updates EEPROM address (x) with value (y)");
        println("/  - PIN.x.y - Updates PIN (x) with value of (y)"); 
        println("/    [ Value should be 0 or 1 ONLY!]");
        println("/  - Call.x - Calls current value of position (x) in array");
        println("/  - Varu.x.y - Updates the position (x) with value of (y) in array");
        println("/");
        println("/");
        println("/  Timer values should stay within value of 5100");
        println("/");
      }else {
        String result = temp.substring(0,6);
      //if(temp.contains("Update"){
        if("Update".equals(result)){
          String apple = temp.substring(7,8);
          String pear = temp.substring(9,temp.length());
          int orange = Integer.parseInt(apple);
          int grape = Integer.parseInt(pear);
          pin[orange] = grape;
        } else {
          myPort.write(temp.toUpperCase() + '\n');
          println("Sent: " +temp.toUpperCase());
        }
      }
    }
    boolean StrTest = test.getName().startsWith("Timer");

    if(StrTest == true){
      println("Sending EEPROM Update to controller");
      println("Updating Timer: " +test.getId() +" to Value: " +test.getStringValue());
      Timefunc(test.getId()-1, test.getStringValue());
    }
  }
}
public void button1(){
  println("Sent: pin.10.1");
  myPort.write("PIN.10.1" +endchar);
}
public void button2(){
  println("Sent: pin.10.0");
  myPort.write("PIN.10.0" +endchar);
}
public void button3(){
  println("SYSTEM: Relays On");
  myPort.write("PIN.22.0" +endchar);
  myPort.write("PIN.24.0" +endchar);
  myPort.write("PIN.26.0" +endchar);
  myPort.write("PIN.28.0" +endchar);
  myPort.write("PIN.30.0" +endchar);
  myPort.write("PIN.32.0" +endchar);
  myPort.write("PIN.34.0" +endchar);
  myPort.write("PIN.36.0" +endchar);
}
public void button4(){
  println("SYSTEM: Relays Off");
  myPort.write("PIN.22.1" +endchar);
  myPort.write("PIN.24.1" +endchar);
  myPort.write("PIN.26.1" +endchar);
  myPort.write("PIN.28.1" +endchar);
  myPort.write("PIN.30.1" +endchar);
  myPort.write("PIN.32.1" +endchar);
  myPort.write("PIN.34.1" +endchar);
  myPort.write("PIN.36.1" +endchar);
}
public void Relay1(){
  RelayControl(pin[0], !globalState[0]);
}
public void Relay2(){
  RelayControl(pin[1], !globalState[1]);
}
public void Relay3(){
  RelayControl(pin[2], !globalState[2]);
}
public void Relay4(){
  RelayControl(pin[3], !globalState[3]);
}
public void Relay5(){
  RelayControl(pin[4], !globalState[4]);
}
public void Relay6(){
  RelayControl(pin[5], !globalState[5]);
}
public void Relay7(){
  RelayControl(pin[6], !globalState[6]);
}
public void Relay8(){
  RelayControl(pin[7], !globalState[7]);
}
public void RelayControl(int Id, boolean Flag){
  byte status = 0;
  if(Flag == true){
    status = 1;
  } else {
    status = 0;
  }
  myPort.write("PIN." +Id +'.' +status +endchar);
}

void SensorCheck(int value){
 myPort.write("SC." +value +endchar);
}

public void Timefunc(int Id, String value){
  byte overboard = 0;
  int control = Integer.parseInt(value);
  if(control &gt; 5100){
    control=5100; 
  }
  control = control/10;
  if(control &gt;= 256){
    overboard = 1;
  }
  if(overboard == 0){
    myPort.write("EEPROM." +Id +'.' +control +endchar);
    Id++;
    myPort.write("EEPROM." +Id +'.' +"0" +endchar);
  }
  if(overboard == 1){
    control = control - 255;
    myPort.write("EEPROM." +Id +'.' +"255" +endchar);
    Id++;
    myPort.write("EEPROM." +Id +'.' +control +endchar);
  }
}

void serialEvent(Serial myPort) {
  inByte = myPort.readStringUntil('\n');
  if (inByte != null){
    inByte = trim(inByte);
    println("Recieved: " +inByte);
    if(inByte.contains("PIN.")){
      String result = inByte.substring(4,6);
      char state = inByte.charAt(7);
      boolean isOn;
      if(state == '1'){
        isOn = true;
      }
      else{
       isOn = false; 
      }
      int endresult = parseInt(result);
      for(int i = 0;i&lt;pin.length;i++){
        if (endresult == pin[i]){
          globalState[i] = isOn;
        }
      }
      delay(10);
    }//End of PIN Function
    if(inByte.contains("SEN.")){
      char firstvalue = inByte.charAt(5);
      char secondvalue = inByte.charAt(7);
      int fvresult = parseInt(firstvalue);
      int svresult = parseInt(secondvalue);
      cp5.getId(fvresult);
    }

    if (firstContact == false) {
      if (inByte.equals("&lt;Controller is ready&gt;")) {
        myPort.clear();
        firstContact = true;
        //myPort.write("A");
        println("SYSTEM: Contact Made");
        delay(100);
        println("Control ready!");
      }
    }
  }
}
</code></pre>

<p>The issue resides with this line: 
cp5.getId(fvresult);</p>

<p>How can I format this to send the information to the Textfield controller when it doesn't go thorugh the ControlEvent function?</p>

<p>edit: fixed spelling mistakes.</p>

<p>edit: I have a working example below.  Its just not a "universal" function:</p>

<pre><code>if(inByte.contains("SEN.")){
  char firstvalue = inByte.charAt(5);
  String secondvalue = inByte.substring(6,inByte.length());
  //int fvresult = Integer.parseInt(firstvalue);
  int svresult = Integer.parseInt(secondvalue);
  println(svresult);
  Timer1.setText(secondvalue);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Playing sound randomly with Arduino input trigger</title>
      <link>https://forum.processing.org/two/discussion/22181/playing-sound-randomly-with-arduino-input-trigger</link>
      <pubDate>Mon, 24 Apr 2017 22:34:39 +0000</pubDate>
      <dc:creator>charlotteoppenheim</dc:creator>
      <guid isPermaLink="false">22181@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I am currently writing a program that reacts visually to some touch sensitive electrodes, I have the visuals pretty much perfect, and now I want to add sound. There will be a continuous background ambient sound, but I want to add little 'splash' noises for when an electrode is touched. However I want to use an array so the sound is selected randomly, to prevent annoying repetitive sounds, and I also want to NOT play any 'splash' sounds sometimes, to again add an organic feeling and prevent any repetition. When the PressedArray goes below the 800 threshold, that means the electrode is being pressed. 
Here is my code (as cleaned up as possible):</p>

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

Minim minim;
AudioPlayer bgm;

int count = 2;
AudioPlayer [] splashes = new AudioPlayer[count];

float hue;

//creating variable for colour for later
color c;

//mapping colour and place from electrode array values
float colMap;
float disMape;

int disMap;

color b = color(0, 0, 0);

//arduino port stuff
int lf = 10; //ASCII for end of line or line feed  
Serial myPort;  //the Serial connection to processing

//creating arrays for electrodes
int[] pressedArray = new int[13];
boolean[] isPressed = new boolean[13];
PVector[] pressedPositions = new PVector[13];


void setup() {
  fullScreen();
  colorMode(HSB, 255);

  //loading soundfile
  minim = new Minim(this);

  //background ambience
  bgm = minim.loadFile("ambientloop.wav");
  bgm.loop();

  splashes[0] = minim.loadFile("smallsplash.aiff");
  splashes[1] = minim.loadFile("tinysplash.wav");
  splashes[2] = minim.loadFile("splash2.wav");
  splashes[3] = minim.loadFile("splash3.wav");
  splashes[4] = minim.loadFile("splash4.wav");


  //initial array for electrodes and circles
  for (int i = 0; i &lt; 13; i++) {
    pressedArray[i]= 0;
    pressedPositions[i] = new PVector(0, 0);
    isPressed[i] = false;
  }

  //printing array values for use in code (values go from around 930(when not touching) and 120(when pressing quite hard)
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[3], 57600);
}


void draw() {
  background(0);
  circ(); //it might be useful to run the code as a separate function for now
}


void circ() {

  for (int j=0; j&lt;pressedArray.length-1; j++) {

    //using array values
    if (pressedArray[j]&lt;800) {

      //create new position when electrode IS NOT pressed
      if (isPressed[j] == false) {
        pressedPositions[j] = new PVector(random(width), random(height));
      }

      isPressed[j] = true;

      //mapping colours
      colMap = map(pressedArray[j], 600, 0, 0, 255);
      c = color(colMap, 255, 255, 30);
      b = color(colMap, 255, 255, 0);

      //changing size
      disMape = map(pressedArray[j], 1000, 0, 50, 400);
      disMap = floor(disMape);

      //making nice blurry circles
      for (int k=disMap; k&gt;=0; k-=5) {

        //lerp colour to create gradient for edges, going from full colour to black
        color interA = lerpColor(c, b, map(k, 0, disMap, 0, 1));

        //drawing the ellipses
        noStroke();
        fill(interA);
        ellipse(pressedPositions[j].x, pressedPositions[j].y, k, k);
      }
    } else {
      isPressed[j] = false;
    }
  }
}


//try not to mess with this
void serialEvent (Serial p) {
  try {
    String myString = p.readStringUntil(lf);
    if (myString != null) {
      myString = trim(myString);
      println(myString);
      String[]in = split(myString, '&gt;');
      for (int i = 0; i &lt; in.length; i ++) {
        pressedArray[i] = int(in[i]);
      }
    }
  }
  catch(Exception e) {
  }
}
</code></pre>

<p>I'm aware you might not be able to run this code, as you don't have the physical components, but I'd really appreciate some help.</p>
]]></description>
   </item>
   <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>Drawing the data received from microcontroller.</title>
      <link>https://forum.processing.org/two/discussion/22022/drawing-the-data-received-from-microcontroller</link>
      <pubDate>Sat, 15 Apr 2017 23:23:56 +0000</pubDate>
      <dc:creator>mouser</dc:creator>
      <guid isPermaLink="false">22022@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>First of all I only recently discovered Processing and it has already helped me tremendously in my work. Since I am fairly new to this software, I am a little confused.</p>

<p>I am trying to "draw" the points that I am receiving from my dsPIC microcontroller. I know that I am receiving the correct data since <code>println</code> shows that I do receive them.</p>

<p>A little summary: I am reading a txt file that contains G-code commands for something. I send those commands line by line to my dsPIC, which crunches the data. I then return the coordinates I already obtain from the txt file (through Processing) so that I can hopefully draw them on the work area. I do this instead of extracting directly from the file because I wanna make sure that my microcontroller process the data correctly.</p>

<p>And here comes the rub: my drawing code does not work! I want to draw and connect the points as I receive them so that I can visualize whats happening on the machine in my monitor.</p>

<p>The code seems fairly logical to me, but I guess there are nuances to Processing that I do not know yet. It also does not help that I really am not very familiar with Java coding(only C).</p>

<p>Finally, here is my code:</p>

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

<pre><code> PVector[] vecs;
 Serial myPort;
 String val;
 String[] command;
 int command_num = 0;
 int counter = 0;
 int letter = 0;
 String dummy;
 String dummy2;
 String[] coordinates;
 int vectorcounter = 0;
 int i = 0;
 boolean ender = true;//if false, then endShape to stop drawing
 boolean drawing;  //if true, start drawing
 boolean firstContact = false;

 void setup(){
   size(800,800);
   //some Serial and file reading setup
  vecs = new PVector[command.length];//irrelevant, doesnt work
}

void draw(){

  beginShape();
  while(ender){
    if(drawing){
      vertex(float(coordinates[0]),float(coordinates[1]));
      drawing = false;//toggle to avoid infinite loop
     }
   }
  endShape(CLOSE);

 }

 void serialEvent(Serial myPort){
     //put incoming data into a string
     ///\n delimiter indicating end of packet
     val = myPort.readStringUntil('\n');

    if((val != null)){      //if null, do nothing
    println("[dspic]"+val);
    if(firstContact == false){
      //code to establish contact with dspic
     }
     else{
     if(val.equals("Next!\n")){
        dummy = command[command_num];
        if(command_num == command.length - 1){

        ender = false;
        println("Reached end of file. Please re-run.\n");
        while(true){}
       }
       while(counter&lt;dummy.length()){
         //some code to send the commands to dspic
       }

      if(val.charAt(0) == 'X'){///HERES WHERE I RECEIVE THE DATA
         dummy2 = val.substring(2);
         coordinates = split(dummy2,",");
         println(coordinates[0]+coordinates[1]);///***
         drawing = true;
       }
     }
  }
   }`
</code></pre>

<p>Please pardon some seemingly random variables and ommitted because I have been experimenting to no avail. My current logic is that in serialEvent I set <code>drawing</code> to <code>true</code> when I receive the data, so that the <code>draw()</code> function knows when to draw. I also toggle the boolean there.</p>

<p>I already know that I am receiving the correct coordinates at <code>println(coordinates[0]+coordinates[1]);///***</code>, but I just cant draw it at the <code>draw()</code> routine, even though global variables are involved. I am under the impression that the whole code at <code>serialEvent</code> only executes when there is serial data available, so I plan to use the rest of the time to draw in the <code>draw</code> function. But that doesnt work apparently.</p>

<p>I would really appreciate any help. Thanks! I might not reply quick though because I lost a night's sleep due to this problem. :))</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>serial connection opened in a parallel thread</title>
      <link>https://forum.processing.org/two/discussion/21123/serial-connection-opened-in-a-parallel-thread</link>
      <pubDate>Fri, 03 Mar 2017 12:17:33 +0000</pubDate>
      <dc:creator>secondsky</dc:creator>
      <guid isPermaLink="false">21123@/two/discussions</guid>
      <description><![CDATA[<p>Hi all, i would like to have a serial port declared into an object running a parallel thread (to feed a drawing machine with gcode).</p>

<p>Now, if if i try to open it like this:</p>

<pre><code>myPort = new Serial(this, Serial.list()[0], 57600);
</code></pre>

<p>As i would do usually, it don't works, it say: <strong>The constructor Serial(PLOT.Controller, String, int) is undefined</strong></p>

<p>So if i try:</p>

<pre><code>myPort = new Serial(new PApplet(), Serial.list()[0], 57600);
</code></pre>

<p>I can send command over it.</p>

<p>But if i try to declare a void calle serialEvent() in my class, it does not receive nothing.
And if i try:</p>

<pre><code><a href="/two/profile/Override">@Override</a>  void serialEvent(Serial p) { 
  String inString = p.readString(); 
  println(inString);
} 
</code></pre>

<p>It thell me: <strong>The method serialEvent(Serial) of type PLOT.Controller must override or implement a supertype method</strong></p>

<p>What i'm doing is having a method like this, called at any thread cycle:</p>

<pre><code> void serialCheck(){
        while(serialPort.available() &gt; 0){
           String incoming  = serialPort.readStringUntil('\n');
           if(incoming != null)print(incoming);
        }
      }
</code></pre>

<p>And looks like working, but i don't know if will be stable or there are better ways.
Any suggestions?</p>

<p>Thanks</p>
]]></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>How to read and understand serial data?</title>
      <link>https://forum.processing.org/two/discussion/20318/how-to-read-and-understand-serial-data</link>
      <pubDate>Tue, 17 Jan 2017 14:35:04 +0000</pubDate>
      <dc:creator>blyk</dc:creator>
      <guid isPermaLink="false">20318@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to connect my Neurosky EEG sensor with processing code without using ThinkGear connector. ThinkGear connector is an application which read serial data and transmit over <strong>WebSocket</strong> so that other application can listen to that <strong>WebSocket</strong> and use the data. It transmit data like eSense, raw, eyeblink (single) as JSON.</p>

<p><strong>Problem</strong> - Using websocket I can connect with the device and receive  JSON data but this JSON doesn't contain double eye blink data which is really crucial for me hence I want to write my own ThinkGear like emulator in processing.</p>

<p><strong>PROBLEM PART 1</strong></p>

<p>I have been tying to read serial data using processing and I was successful but now I don't know how to interpret this data. I have been trying to read <a rel="nofollow" href="http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol">ThinkGear communication protocol</a> but everything was going over my head. I hope someone will help me to fill this :) :)<br />
There are two important things I need to help to understand are these -</p>

<p>A.  <a rel="nofollow" href="http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol#thinkgear_packets">Packet Structure</a>
 B.  <a rel="nofollow" href="http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol#step-by-step_guide_to_parsing_a_packet">Packet Parsing Guide</a></p>

<p><strong>PROBLEM PART 2</strong></p>

<p>I don't understand the use of <strong>myPort.buffer(12);</strong>. Also what is the point of setting byte[] inBuffer = new byte[8] if it is going to take buffer size as set in the beginning with myPort. What is the point of using <strong>myPort.readBytes(inBuffer);</strong> when <strong>inBuffer</strong> give the same values as without using <strong>readBytes()</strong>. Why myPort.buffer(size) affect the byte[] size even though I hardcoded it to 8 and how come it is taking 12 values even after hardcoding byte[] size to 8?</p>

<p><strong>CODE</strong></p>

<pre><code>    import processing.serial.*;
    Serial myPort;  // Create object from Serial class
    String myString="";  
    String arrayval="";  

    byte[] inBufferfinal = new byte[12]; 
    void setup() {
      size(600, 400); 
      String[] portName = Serial.list();
      for (int i=0; i&lt;portName.length; i++) {
        if (portName[i]!=null) {
          myPort = new Serial(this, portName[i], 9600); // baudrate: 57600, 9600, 115400
          myPort.buffer(12);
          println(portName[i]  + " " + i);
        }
      }
      //frameRate(4);
    }

    void draw() {  
      background(255);
      visualizer(12, inBufferfinal );
      fill(0);
      //textAlign(CENTER);
      //text(myString, width/2, height/2);
    }

    void serialEvent(Serial myPort) {
      myString = "";
      arrayval = ""; 
      byte[] inBuffer = new byte[8];
      while (myPort.available () &gt; 0) {
        inBuffer = myPort.readBytes();
        myPort.readBytes(inBuffer);
        inBufferfinal = inBuffer;
        println(inBuffer, inBuffer.length);
        if (inBuffer != null) {
          for (int i=0; i&lt;inBuffer.length; i++) {
            myString = myString + hex(inBuffer[i])+" , " ;
            arrayval = arrayval+ i +  " , ";
          }
        }
      }
    }

    void visualizer(int lengthofbyte, byte[] val) {
      noStroke();
      fill(0);
      for (int i=0; i&lt;lengthofbyte; i++) {
        int h = val[i];  
        rect(230, i*20+20, h, 20); 
        text(h, 20, i*20+40);
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>moving an ellipse in steps.</title>
      <link>https://forum.processing.org/two/discussion/21103/moving-an-ellipse-in-steps</link>
      <pubDate>Thu, 02 Mar 2017 14:20:28 +0000</pubDate>
      <dc:creator>Yami89</dc:creator>
      <guid isPermaLink="false">21103@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to write a code which moves an ellipse when it reads a particular serial input. But what happens is when it receives the particular value it moves all the way to the end of the screen. Looking at the code I can work out yes thats what will happen. But previously I was able to do the same thing with similar code and it worked out perfectly. I tried copying and pasting that codes into it but still it doesn't move in steps.</p>

<p>Here is the code I'm working on
    import processing.serial.*;
    Serial myPort;  // Create object from Serial class
    int val;</p>

<pre><code>int Xpos = 200;
int Ypos = 200;


void setup() {
  size(400, 400);
  noStroke();
  String portName = Serial.list()[2]; 
  myPort = new Serial(this, portName, 9600);
}
void draw() {

  move();


  background(123);
  ellipse(Xpos, Ypos, 80, 80);
}




void serialEvent(Serial myPort) {
  val = myPort.read();
  println(val);
}

void move(){

  if (val == 1) {
    if (Ypos&gt;0) {
      Ypos = Ypos - 2;
    }
  }
  if (val == 2) {
    if (Ypos&lt;height) {
      Ypos = Ypos + 2;
    }
  }
  if (val == 3) {
    if (Xpos&gt;0) {
      Xpos = Xpos -2;
    }
  }
  if (val == 4) {
    if (Xpos&lt; width) {
      Xpos = Xpos + 2;
    }
  }


}
</code></pre>
]]></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>Many Serial Com Opened... how to manage them?</title>
      <link>https://forum.processing.org/two/discussion/20954/many-serial-com-opened-how-to-manage-them</link>
      <pubDate>Wed, 22 Feb 2017 18:19:48 +0000</pubDate>
      <dc:creator>mikearding</dc:creator>
      <guid isPermaLink="false">20954@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I need to connect via serial com many uart devices.
There are two piece of code in my project.</p>

<p>The first is the open serial channel</p>

<pre><code>    // initialize the serial port selected in the listBox
    byte initSerial(String portName, int portIDX, int portWhat) {
      byte init_com = 0;
      if (portWhat==1) {
        try {
          Serial_Port[portIDX] = new Serial(this, portName, 115200, 'N', 8, 1);
          init_com=1;
          Serial_Port_WatchDog[portIDX] = millis() + CONTROLLER_WATHCDOG;
        } 
        catch (RuntimeException e) {
          init_com=0;
        }
      } else {
        init_com=0;
        Serial_Port[portIDX].stop();
      }
      return init_com;
    }
</code></pre>

<p>The second part of code is here:</p>

<pre><code>void serialEvent(Serial p) {
      if (p.available() == Frame_Size_Read) {
        Serial_Buffer_Discr++;
        if (Serial_Buffer_Pointer &lt; Serial_Buffer_Size) { 
          Serial_Buffer_Pointer++;
          if (Serial_Buffer_Max &lt; Serial_Buffer_Pointer) { Serial_Buffer_Max = Serial_Buffer_Pointer; }
          if (Serial_Buffer_Act &lt; Serial_Buffer_Pointer) { Serial_Buffer_Act = Serial_Buffer_Pointer; }
        } else { 
          Serial_Buffer_Pointer = 0; 
        }
        inBufRegister[Serial_Buffer_Pointer] = p.readBytes();
      }
    }
</code></pre>

<p>in other part of code I read all data in inBufRegister array.</p>

<p>The first question: I need to know from which com port the data become in serialEvent() routine, like COM1, COM2... and so on.
The second question: during data receiving I often (I think due to a high amount of data incoming) receive a "Error, disabling serialEvent() for COMx". Whats happen?
And somethime seems to have a desyncronization between the uart device and the processing serialEvent routine. There is a method to empty serial buffer and force syncronization?
Many thanks to all.</p>
]]></description>
   </item>
   <item>
      <title>Error, disabling serialEvent() for /dev/ttyUSB0 null</title>
      <link>https://forum.processing.org/two/discussion/20939/error-disabling-serialevent-for-dev-ttyusb0-null</link>
      <pubDate>Wed, 22 Feb 2017 02:32:10 +0000</pubDate>
      <dc:creator>jiapei100</dc:creator>
      <guid isPermaLink="false">20939@/two/discussions</guid>
      <description><![CDATA[<p>Looks like Processing is NOT quite stable?
I'm working under Ubuntu 16.04 with an Arduino, and tesing a BNO055 with the tutorial here:
<a rel="nofollow" href="https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/wiring-and-test">https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/wiring-and-test</a></p>

<p>However, it seems I met the error message as titled frequently...
<strong>Error, disabling serialEvent() for /dev/ttyUSB0 null</strong></p>

<p>Any suggestions?</p>
]]></description>
   </item>
   <item>
      <title>error with serial</title>
      <link>https://forum.processing.org/two/discussion/20717/error-with-serial</link>
      <pubDate>Wed, 08 Feb 2017 15:23:20 +0000</pubDate>
      <dc:creator>plux</dc:creator>
      <guid isPermaLink="false">20717@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I've successfully done this long time ago but for some reason now it's not working.
I'm just trying to read data from arduino via serial. I'm sending a string with 3 values (range 0-360), but I'm getting "Error, disabling serialEvent() for COM3 null" in Processing and can't figure out the issue.</p>

<p>Here's my code</p>

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

Serial myPort;

void setup() {
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

} 

void draw() { 

}

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

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

  print("X: " + gyro[0]);
  print(", Y: " + gyro[1]);
  println(", Z: " + gyro[2]);
}
</code></pre>

<p>It's pretty much the same code I've used before but no idea what's wrong..help?</p>

<p>here's my arduino printing code</p>

<pre><code>  //the vars are integers range 0 -360
  Serial.print(GyX);
  Serial.print(',');
  Serial.print(GyY);
  Serial.print(',');
  Serial.print(GyZ);
  Serial.print('\n');
</code></pre>

<p>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>
   </channel>
</rss>