<?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/p3/feed.rss?Tag=bufferuntil%28%29</link>
      <pubDate>Sun, 08 Aug 2021 20:42:13 +0000</pubDate>
         <description>Tagged with bufferuntil() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedbufferuntil%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Drawing inside Serial event handler</title>
      <link>https://forum.processing.org/two/discussion/13155/drawing-inside-serial-event-handler</link>
      <pubDate>Wed, 21 Oct 2015 19:39:21 +0000</pubDate>
      <dc:creator>liudr</dc:creator>
      <guid isPermaLink="false">13155@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I've been away from processing for a long time. Coming back to do a quick o-scope project that involves plotting numbers coming from serial port. I'm using serial event handler according to an ancient post on arduino's website. The code seems to work in Processing 2, but not in processing 3 or old 1.x. In 3, the data are coming in and the line functions are called but there seems to be a lack of actual drawing so the screen is blank. What am I doing wrong?</p>

<p>Here is the code. Code tag seems to not work on my computer.</p>

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

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

float oldinByte=0;
float oldinFloat=0;
float inFloat=0;
float trigger_threshold=0.5;
String trigger_mode="POS EDGE";

void setup () 
{
  // set the window size:
  size(320, 240);
  //println("Height is"+height);

  // 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], 250000);

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

  // set inital background:
  background(0);
}

void draw () 
{
}

void mouseClicked()
{
  if (trigger_mode=="POS EDGE") trigger_mode="AUTO";
  else trigger_mode="POS EDGE";
}

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:
    oldinFloat=inFloat;
    inFloat = float(inString);
    float inByte = map(inFloat, -10, 10, 0, height);
    //println(inByte);
    // draw the line:

    //Trigger
    if (trigger_mode=="POS EDGE")
    { 
      if (xPos==0)
      {
        if(!((oldinFloat&lt;trigger_threshold)&amp;&amp;(inFloat&gt;trigger_threshold)&amp;&amp;(inFloat&gt;oldinFloat))) return;
      }
    }
    stroke(0,0,0);
    line(xPos,0,xPos,height);
    line(xPos+1,0,xPos+1,height);
    stroke(0,255,0);
    if (xPos==0) 
    {
      line(xPos, height-inByte, xPos, height-inByte);
    }
    else line(xPos, height-inByte, xPos-2, height-oldinByte);
    oldinByte=inByte;

    // at the edge of the screen, go back to the beginning:
    if (xPos &gt;= width) {
      text(trigger_mode,width-70,height-10);
      xPos = 0;
      //background(0);
    } else {
      // increment the horizontal position:
      xPos+=2;
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>plotting x and y coordinates</title>
      <link>https://forum.processing.org/two/discussion/16948/plotting-x-and-y-coordinates</link>
      <pubDate>Thu, 02 Jun 2016 09:37:51 +0000</pubDate>
      <dc:creator>Tipikosh</dc:creator>
      <guid isPermaLink="false">16948@/two/discussions</guid>
      <description><![CDATA[<p>greetings, 
i am trying to plot x and y coordinates from a touchpad connected to my pc via arduino. my arduino gives me a string that looks like that
233,672,0
the first part is my x coordinate, my second part is the y coordinate and that last part, is a 0 or 1 to tell me if there was a touch or not.
until now i can see where my coordinates are with ellipse function, but i still cant get it to simply draw a line connecting all positions of my postion on the touchpad.
my plan is to use the touchpad to write a letter, and when the letter is done written, i want to compare the letter that was drawn with another saved one on my pc.
any help i would be thankful, here is my code</p>
]]></description>
   </item>
   <item>
      <title>Processing with Arduino - void serialEvent</title>
      <link>https://forum.processing.org/two/discussion/16618/processing-with-arduino-void-serialevent</link>
      <pubDate>Sun, 15 May 2016 16:24:22 +0000</pubDate>
      <dc:creator>Itachi</dc:creator>
      <guid isPermaLink="false">16618@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I have a problem with my Processing and Arduino code. I don't know if my problem come forum my Arduino or Processing code. I have a project, I have to display the temperature (°C), the height (kg), the sound (dB), the humidity and the counting bees. The counting bees ? Yeah, this is an interface that displays the values ​​that give integrated sensors in intelligent hive.
Next, my interface is finished but I have one problem. I'm using a potentiometer to do a simulation with the interface like that : <a rel="nofollow" href="https://trello-attachments.s3.amazonaws.com/56dc71ee6c67de69f4cc3c57/1627x525/dda158fae56235f58bb8dff829d84ed6/ein_teil.png">simulation</a>. As you can see, we have the temperature. But now, I want to display the height, the sound, the counting bees and the humidity. With Arduino, I have a potentiometer and I do simulation, I'm using analogRead(A0) for the temperature, analogRead(A1) for the height and others... The problem is when I'm in A0 (in my arduino card), I have the temperature and and the other values. What I want is that when I 'm on A0, I only have the temperature and not other values. And when I'm on A1, I have only the height...</p>

<p><strong>PS : You can check this thread first</strong> : <a href="https://forum.processing.org/two/discussion/15328/g4p-library-processing-with-arduino-isis-proteus-and-vspe#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/15328/g4p-library-processing-with-arduino-isis-proteus-and-vspe#latest</a></p>

<p><strong>My Processing code</strong> :</p>

<pre><code>// Global variable created 
void serialEvent (Serial monPort)
{
  //Récupération sur le port série de la tension sous forme de chaine de caractères
  String listeInfo = monPort.readStringUntil('\n');

  if(listeInfo == null)
    return; //Aucune données reçues

  String[] tableauInfo = listeInfo.split(";"); //Chacun des 5 premières cases contient une info

  if (tableauInfo.length != 5)
    return; //Manque des données

    /*** TEMPERATURe ***/
    String tensionCar = trim(tableauInfo[0]); // Suppression des blancs au début et à la fin de la chaine de caractère
    int tensionNum = int(tensionCar);  // Conversion de la tension codée en CHAR en valeur décimale puis calcul température
    temperature = round(((500 * tensionNum) / (3.3 * 1024)) - 50.0);

    /*** MASSE ***/
    String masse2 = trim(tableauInfo[1]);
    int tension2Num = int(masse2);
    masse = round(((500 * tension2Num) / (3.3 * 1024)) - 50.0);

    /*** HUMIDITE ***/
    String humidite = (tableauInfo[2]);

    /*** COMPTAGE ***/
    String comptage = (tableauInfo[3]);

    /*** SON ***/ 
    String son = (tableauInfo[4]);


    //Suite du code...
}
</code></pre>

<p>My Arduino code :</p>

<pre><code>int temperature;
int masse;
int humidite;
int comptage;
int son;

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

void loop()
  {
    //Lecture des données
    temperature = analogRead(A1);
    masse = analogRead(A2);
    humidite = analogRead(A3);  
    comptage = analogRead(A4); 
    son = analogRead(A5);

    //Écriture des données
    Serial.print(temperature);
    Serial.print(";");
    Serial.print(masse);
    Serial.print(";");
    Serial.print(humidite);
    Serial.print(";");
    Serial.print(comptage);
    Serial.print(";");
    Serial.println(son);
    Serial.print(";");

    delay(1000);
  }
</code></pre>

<p>I have to make this project for the 17/05, I hope to help in the meantime. (Can skype for more information)
Regards,</p>
]]></description>
   </item>
   <item>
      <title>NullPointerExeption error in array</title>
      <link>https://forum.processing.org/two/discussion/16533/nullpointerexeption-error-in-array</link>
      <pubDate>Wed, 11 May 2016 00:23:11 +0000</pubDate>
      <dc:creator>spyguy518</dc:creator>
      <guid isPermaLink="false">16533@/two/discussions</guid>
      <description><![CDATA[<p>I continue to get a "NullPointerExeption" error on an array (defined on line 12) that takes data from a Serial port (data from two potentiometers) , and splits it. The array appears to be initialized correctly. Does anybody know what may be causing this? I have included the code (which is very long) below. Thank you for any help.</p>

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

// initialize all variables
Serial myPort;  // Create object from Serial class
public String input;  // Data received from the serial port
PFont font;
int xPosB= 1;         // horizontal position of the graph
int xPosT= 1;
boolean allOn = false;
boolean brakeOn = false;
boolean throttleOn = false;
String arrdata[] =  input.split("/n", 2);

// remove non-numerical characters to create graphable string
String graphableB[] = arrdata[0].split("Brake:", 2);
String graphableT[] = arrdata[1].split("Throttle:", 2);
//convert to integer for graphing
int inByteT = int(graphableT[2]);
int inByteB = int(graphableB[2]);


void setup() {
  size(925, 800);

  //initialize text
  font = createFont("Agency FB", 16, true); //create font
  textFont(font, 36);

  //initialize data acquisition
  //String data = Integer.toString(input); 
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

  // 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(#717070);

  //P5 Setup
  // create a toggle and change the default look to a (on/off) switch look

  import controlP5.*;

  ControlP5 cp0;
  ControlP5 cp1;
  ControlP5 cp2;

  smooth();
  cp0 = new ControlP5(this);
  cp1 = new ControlP5(this);
  cp2 = new ControlP5(this);

  cp0.addToggle("allOn")
    .setPosition(40, 250)
    .setSize(50, 20)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    .setCaptionLabel("ALL")
    ;

  cp1.addToggle("brakeOn")
    .setPosition(40, 190)
    .setSize(50, 20)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    .setCaptionLabel("BRAKE")
    ;

  cp2.addToggle("throttleOn")
    .setPosition(40, 130)
    .setSize(50, 20)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    .setCaptionLabel("THROTTLE")
    ;
}

void draw(){

  //initialize text print
  background(255);
  textFont(font, 16);
  fill(#FF0324);

  if ( myPort.available() &gt; 0) {  // If data is available,
    input = myPort.readString();    // read it and store it in data
    text(arrdata[0], 400, 400);
    text(arrdata[1], 500, 500);
  } else {
    text("NO DATA", 350, 350);
  }

  graphDrawBrake(allOn, brakeOn);
  graphDrawThrottle(allOn, throttleOn);
}


void graphDrawBrake (boolean allOn, boolean brakeOn) {

  while (allOn == true) {
    while (brakeOn == true) {
      // draw the line:
      stroke(#FF0000);
      line(xPosB, height, xPosB, height - inByteB);

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

void graphDrawThrottle (boolean allOn, boolean throttleOn) {

  while (allOn == true) {
    while (throttleOn == true) {
      // draw the line:
      stroke(#50D85A);
      line(xPosT, height, xPosT, height - inByteT);

      // at the edge of the screen, go back to the beginning:
      if (xPosT &lt; 400 || xPosT &gt;= 800) {
        xPosT = 400;
        background(#717070);
      } else {
        // increment the horizontal position:
        xPosT++;
      }
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>serialEvent() bugs</title>
      <link>https://forum.processing.org/two/discussion/16481/serialevent-bugs</link>
      <pubDate>Sat, 07 May 2016 20:32:00 +0000</pubDate>
      <dc:creator>MaxW</dc:creator>
      <guid isPermaLink="false">16481@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm pulling my hair out with the buggy serial library in Processing. I'll try and explain without pasting reams of code here.</p>

<p>In my setup, I'm sending a node discovery command to an XBee co-ordinator (AT command ND), running in API mode. In my serialEvent, I used to wait for the Xbee delimiter (7E) using bufferUntil(0x7E), then do a port.read() to get the LSB of the packet length, then another port.read() for the MSB. I would then do a loop of [LSB] iterations to read in the packet.</p>

<p>port.buffer(1) <em>must</em> be set, btw, otherwise all kinds of weird behaviour results. Using different values truncated the packets, which are of varying length, naturally, so you have to trigger on each seperate byte arrival.</p>

<p>The XBee replies (in my two device setup) with two packets, one containing the name of the co-ordinator, and one containing the name of the end device. However, it became apparent that bufferUntil(0x7E) would produce the delimiter first time, and the 00 of the MSB the next, skipping the 7E. Why?</p>

<p>After trying numerous workarounds, I gave up, and started writing a ring buffer. Initially, I could watch the two XBee packets hit it, totalling the correct length, so I went back to the Arduino code that I'm using to send data to Processing.</p>

<p>The data packets are hitting the ring buffer, which is now filling up nicely. However, NOW, if I stop the Processing sketch, and let the Arduino continue to send packets, THEN stop the Arduino sketch, THEN start the Processing sketch, I get 130 bytes, always 130 bytes, sitting in the buffer, even though it's inside a class, and I'm instantiating it in my setup. Obviously, the serialEvent is firing when the sketch is started, and all attempts to clear it down are failing miserably.</p>

<p>I've tried port.clear(), a loop of port.read() inside a while(port.available() &gt; 0), and nothing is working. Obviously, I need everything to be initialised when I stop and then run the Processing sketch, as eventually, data will be coming in from numerous devices, and I have to have a zero'd ring buffer, from which to start extracting valid packets.</p>

<p>If the bufferUntil() method wasn't so flaky, I wouldn't need to be faffing around with a ring buffer anyway. I hope I've explained this clearly. Before anybody says 'post some code snippets', you have to realise that all my workaround stuff is relevant, and has been cut and replaced with numerous different attempts at curing this issue.</p>

<p>I could do with some help here, before I un-install Processing and look  for a more robust piece of s/w for my project. I simply cannot be the only person experiencing these issues.</p>

<p>Thanks.</p>

<p>Max</p>
]]></description>
   </item>
   <item>
      <title>Random Spikes in Real Time Data Graphing</title>
      <link>https://forum.processing.org/two/discussion/16416/random-spikes-in-real-time-data-graphing</link>
      <pubDate>Wed, 04 May 2016 01:25:14 +0000</pubDate>
      <dc:creator>agustinpfrpa</dc:creator>
      <guid isPermaLink="false">16416@/two/discussions</guid>
      <description><![CDATA[<p>Hi! So I am using this program to plot data from serial coming from an accelerometer connected to an Arduino. As you can see there are random spikes appearing in the plot. I know that it is not because of the data because I am looking at the data that is being transmitted and none of the points match with those in the image. Any suggestion as to what I can do to get rid of the random spikes? Thank you!</p>

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

<p>Serial myPort;        // The serial port
int xPos = 0;         // horizontal position of the graph
float inByte = 0;
int lastxPos = 1;
int lastHeight = 0;</p>

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

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

<p>// 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, "COM3", 115200);</p>

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

<p>//writer = createWriter("new_data.txt");
  // set inital background:
  background(0);
}
void draw () {
  // draw the line:
  stroke(255,255,255);
    strokeWeight(1);
    //delay(5);
    line(lastxPos, lastHeight, xPos, height - inByte);
    lastxPos = xPos;
    lastHeight = int(height - inByte);
if (xPos &gt;= width) {
    xPos = 0;
    lastxPos = 0;
    background(0);
  } else {
    // increment the horizontal position:
    xPos++;
  }</p>

<p>}</p>

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

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

<pre><code>inString = trim(inString);
// convert to an int and map to the screen height:
inByte = float(inString);
//println(inByte);    
inByte = constrain(inByte, 0, 32768);
println(inByte/16384.0);
inByte = map(inByte, 0, 32768, 0, height);
</code></pre>

<p>}</p>

<p>}
}`</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/328/WHYD2YO367A4.png" alt="RandomLines" title="RandomLines" /></p>
]]></description>
   </item>
   <item>
      <title>Sending constant float data from Arduino to Processing's Python</title>
      <link>https://forum.processing.org/two/discussion/16400/sending-constant-float-data-from-arduino-to-processing-s-python</link>
      <pubDate>Tue, 03 May 2016 11:10:24 +0000</pubDate>
      <dc:creator>ClodeVFX</dc:creator>
      <guid isPermaLink="false">16400@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys,</p>

<p>I have a little project I'm working on involving IMU chips and arduinos, and I'm trying to send real world data from my arduino to processing.</p>

<p>Problem is it doesn't seem to be working... I kind of got it working before but it ended up lagging out apparently due to the arduino sending too much data to processing.</p>

<p>Here is the code, I have hacked the Arduino code off an existing library. The only part of the Arduino code that matters is the bottom section of it, where I println it.</p>

<p>Any help would really really be appreciated!</p>

<p><img src="http://i.imgur.com/ikgzVne.png" alt="" /></p>
]]></description>
   </item>
   <item>
      <title>How to scale webcamera view when face is detected?</title>
      <link>https://forum.processing.org/two/discussion/15964/how-to-scale-webcamera-view-when-face-is-detected</link>
      <pubDate>Mon, 11 Apr 2016 15:06:08 +0000</pubDate>
      <dc:creator>Chris78</dc:creator>
      <guid isPermaLink="false">15964@/two/discussions</guid>
      <description><![CDATA[<p>Webcamera through Processing detects the face, when arduino proximity sensor is activated and put a rectangle around the face, what I would like to do is to make the whole view or just what is inside the rectangle bigger (scale it twice) or rotate or change the collor, when the face is detected. How should I amend my code? Many thanks
This is my processing code:</p>

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

import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;

boolean playVid = false;

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

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

  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); 

  video.start();
}

void draw() {
  if (myPort.available() &gt; 0) {
    String unoMessage = myPort.readStringUntil('@');

    if (unoMessage != null) { 
      if (unoMessage.equals("StartCamera@")) {
        playVid = true;
        println(unoMessage);
      }
    }
  }

  if (playVid) {
    scale(2);
    opencv.loadImage(video);

    image(video, 0, 0 );

    noFill();
    stroke(0, 255, 0);
    strokeWeight(3);
    Rectangle[] faces = opencv.detect();
    println(faces.length);

    for (int i = 0; i &lt; faces.length; i++) {
      println(faces[i].x + "," + faces[i].y);
      rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    }
  }
}

void captureEvent(Capture c) {
  c.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>myPort.available always 0</title>
      <link>https://forum.processing.org/two/discussion/14534/myport-available-always-0</link>
      <pubDate>Tue, 19 Jan 2016 15:35:27 +0000</pubDate>
      <dc:creator>langrenne</dc:creator>
      <guid isPermaLink="false">14534@/two/discussions</guid>
      <description><![CDATA[<p>Hy,</p>

<p>I'm on Linux kubuntu.
I would like receive data from an arduino nano (3 axis motion for head tracking).
The arduino code works because I can read data with Pure Data (Pd).
The arduino is on port [32] (/dev/ttyUSB0)</p>

<p>I use the common code:</p>

<pre><code>// Example by Tom Igoe

import processing.serial.*;

int lf = 10;    // Linefeed in ASCII
String myString = null;
Serial myPort;  // The serial port

void setup() {
  // 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()[32], 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;
}

void draw() {
  println(myPort.available());

  while (myPort.available() &gt; 0) {
    myString = myPort.readStringUntil(lf);
    if (myString != null) {
      println(myString);
    }
  }
}
</code></pre>

<p>But myPort.available is always 0. I can't read anything.</p>

<p>Can someone help me ?</p>

<p>thanks</p>
]]></description>
   </item>
   <item>
      <title>Using Processing to display a graph of voltage change over time.</title>
      <link>https://forum.processing.org/two/discussion/15702/using-processing-to-display-a-graph-of-voltage-change-over-time</link>
      <pubDate>Sat, 26 Mar 2016 21:18:41 +0000</pubDate>
      <dc:creator>vysero</dc:creator>
      <guid isPermaLink="false">15702@/two/discussions</guid>
      <description><![CDATA[<p>Hello there so I am brand spanking new to processing and my Arduino Uno. The project I am doing is a salinity detector (of sorts). However, for the short term, instead of detecting salinity, I am detecting changes in light with a photo-resistor in the form of voltage differences. I am then attempting to graph the change in voltage over time. My code is coming from a tutorial for processing (have never used until now) and now I want to add some additional complexity to the graphed response, here is my code so far:</p>

<p>Arduino Uno:</p>

<pre><code>int val = 0; // variable to store value read at analog pin 3

void setup(){
  Serial.begin(9600); // set up to print to monitor, baud rate = 9600
}

void loop(){
  val = analogRead(3); // read analog input pin 3
  Serial.println(val); // print value to serial monitor
  delay(2);

}
</code></pre>

<p>and Processor:</p>

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

Serial myPort;  // Create object from Serial class
int xPos = 1;
float inByte = 0;     // Data received from the serial port

void setup() 
{
// set window size:
  size(400, 300);
// set up port
String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600); 

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

// set inital background
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(0);
  }else{
    // increment the horizontal postion:
    xPos++;
  }
}

void serialEvent (Serial myPort){

  // get ASCII string:
  String inString = myPort.readStringUntil('\n');

  if(inString !=null){

    // trim off any whitespace:
    inString = trim(inString);

    // convert to an int and map the the screen height:
    inByte = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height);
  }

}
</code></pre>

<p>I know that the value's being displayed in the output window are 1024'th's of the actual voltage so a value of 512 = 2.5v. What I would like though is for that value to be displayed on the x axis of the graph in the form of a scale. I want to add x and y axis labels to my graph.</p>

<p>For instance, the y label could be 0-1000 and the x label would be in seconds. I think the y axis shouldn't be to hard to include because its constant not sure how to edit this output graph though.. is it some kind of GUI? Also, would it even be possible to add an x axis label that scales itself as time goes on?</p>

<p>Maybe I should just forget about x axis labeling or maybe I will need to keep track of the information and send it to a file to be graphed later??</p>

<p>Not entirely sure how I should go about the project from here, any advice? I do know that eventually I am going to need at least a y axis label because I want to detect changes in salinity over time from saline rich water to less saline rich water (I will poor in fresh water). My salinity detector will just be two nails spaced about 1 cm apart and will be connected to the circuit in the same configuration as my photo-resistor circuit. For now, if I could just get a y label and a title to the graph that would be good.</p>
]]></description>
   </item>
   <item>
      <title>Arduino and Processing</title>
      <link>https://forum.processing.org/two/discussion/15102/arduino-and-processing</link>
      <pubDate>Wed, 24 Feb 2016 23:14:15 +0000</pubDate>
      <dc:creator>iLegendX</dc:creator>
      <guid isPermaLink="false">15102@/two/discussions</guid>
      <description><![CDATA[<p>I have the arduino and ultrasonic HC-SR04. I want to help please us.
The arduino want to measure the distance and what gives the serial. Communicates with the processing and when the distance is greater than 150cm displays an image, if less playing video.
My problem is that I run the processing but the video plays either away or close.
Please help me. I beginner!!</p>

<p>Arduino is from a library NewPing
    // ---------------------------------------------------------------------------
    // Example NewPing library sketch that does a ping about 20 times per second.
    // ---------------------------------------------------------------------------</p>

<pre><code>#include &lt;NewPing.h&gt;

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
  Serial.println("cm");
}
</code></pre>

<p>Processing</p>

<pre><code>// Video
import processing.video.*;
Movie movie;

// Image
PImage img;  // Declare variable "a" of type PImage

// Serial
import processing.serial.*;
Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port


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

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

  // Load and play the video in a loop
  movie = new Movie(this, "transit.mov");
  movie.loop();
  img = loadImage("moonwalk.jpg");  // Load the image into the program
}

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

void draw() {
  if (movie.available() == true) {
    movie.read(); 
  }
  image(movie, 0, 0, width, height);

  if ( myPort.available() &gt; 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }  


  if (val&gt;130) {
    image(img, 0, 0);
  } else {
    image(movie, 0, 0, width, height);
  }
  println(val);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Processing + Arduino + Flexiforce</title>
      <link>https://forum.processing.org/two/discussion/15278/processing-arduino-flexiforce</link>
      <pubDate>Fri, 04 Mar 2016 13:13:10 +0000</pubDate>
      <dc:creator>CharlesDesign</dc:creator>
      <guid isPermaLink="false">15278@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>I'm trying to import readings from a Flexiforce sensor however, the values in processing are different than the ones displayed in the Arduino serial monitor but they somehow respond to any force applied on the sensor.</p>

<p>Could anyone clarify what's going on?</p>

<p>Thanks in advance :)</p>

<p>Arduino Code:</p>

<pre><code>void setup()
{
  // Start serial at 9600 baud
  Serial.begin(9600);
}

void loop()
{
  // Read the input on analog pin 0:
  int sensorValue = analogRead(A0);

  //Serial.println(sensorValue);
  Serial.write(sensorValue);

  // Wait 100 milliseconds
  delay(100);
}
</code></pre>

<p>Serial Monitor Value (150gr):</p>

<pre><code>    330
    330
    330
    330
    330
    330
    331
    330
    330
    330
    330
    329
    330
    330
    330
    330
    330
    330
    330
    331
</code></pre>

<p>Processing Code:</p>

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

Serial port;                             // Create object from Serial class 
int val = 0;

void setup() { 
  size(200, 200); 
  frameRate(10); 
  // Open the port that the board is connected to and use the same speed (9600 bps) 
  printArray(Serial.list());
  port = new Serial(this, Serial.list()[3], 9600);
} 

void draw() { 

  if (0 &lt; port.available()) {         // If data is available,
    val = port.read();     // read it and store it in val
  }

  background(255);                       // Set background to white
  println(val);
  float dia = map(val, 0, 300, height*0.1, height*0.9);
  fill(0);
  ellipse(width*0.5, height*0.5, dia, dia);
} 
</code></pre>

<p>Processing Println Values (150gr):</p>

<pre><code>    88
    88
    87
    88
    88
    88
    88
    89
    88
    88
    88
    88
    88
    88
    87
</code></pre>
]]></description>
   </item>
   <item>
      <title>Array Index out of bounds exception error.</title>
      <link>https://forum.processing.org/two/discussion/15206/array-index-out-of-bounds-exception-error</link>
      <pubDate>Mon, 29 Feb 2016 18:51:19 +0000</pubDate>
      <dc:creator>StarsGazer</dc:creator>
      <guid isPermaLink="false">15206@/two/discussions</guid>
      <description><![CDATA[<p>Basically what im trying to do is to communicate an arduino with processing to graph the temperature.</p>

<p>Im sending this from arduino via serial :</p>

<p>Serial.print(superior);
Serial.print(",");
Serial.print(inferior);
Serial.print(",");
Serial.println(valor_sensor_enviar);</p>

<p>delay(2000);</p>

<p><img src="" alt="" />
<img src="https://forum.processing.org/two/uploads/imageupload/930/6I8JO1DEGWKL.jpg" alt="pantallazo1" title="pantallazo1" /></p>

<p>so I basically need to store "superior" and "inferior" and represent the third variable data which is continuosly changing between 50 and 0.</p>

<p>So I tried this :</p>

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

<p>Serial port;</p>

<p>int i,k;
int temp;
String buffer;
int[] valor_anterior=new int[150];
int[] valor_auxiliar=new int[150];
int[] datos=new int[10];
int[] pdatos=new int[10];
int x=65;
int nX=400,nY=400;
int j;
int valor_supeior;
int valor_inferior;
int saltodelinea=10;</p>

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

<p>port = new Serial(this, Serial.list()[1], 9600); 
  background(255);</p>

<p>size(700 ,400);
  }</p>

<p>void draw()
{
if(port.available()&gt;=1){</p>

<pre><code>            buffer = port.readStringUntil(saltodelinea);
            port.clear();
            if (buffer != null) {
            buffer = trim(buffer);
            datos = int(split(buffer, ',')); 
            }}}
</code></pre>

<p>It works for a short period of time and then crashes giving me the error in the title of this post.
Ive been investigating about the error and it seems to be a problem of space in the array I declared. 
Actually im "SUPOSED" so save 3 INTs in a vector which has space for 10 of them, so why does it crash?
Can anyone help me out?</p>
]]></description>
   </item>
   <item>
      <title>Does serial.bufferUntil work with any character?</title>
      <link>https://forum.processing.org/two/discussion/15177/does-serial-bufferuntil-work-with-any-character</link>
      <pubDate>Sun, 28 Feb 2016 18:42:44 +0000</pubDate>
      <dc:creator>RetiredProgrammer</dc:creator>
      <guid isPermaLink="false">15177@/two/discussions</guid>
      <description><![CDATA[<p>Every example I have seen uses either a newline or linefeed. Hoes it work with say *,#,% or ??</p>
]]></description>
   </item>
   <item>
      <title>Drawing of graphs from I2C IMU</title>
      <link>https://forum.processing.org/two/discussion/14988/drawing-of-graphs-from-i2c-imu</link>
      <pubDate>Thu, 18 Feb 2016 10:08:24 +0000</pubDate>
      <dc:creator>dragal</dc:creator>
      <guid isPermaLink="false">14988@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys here is my code. I have tried to draw 3 graphs from arduino. I am reading angle by meaning inegration gyro angle , accelerometer angle and their complementary filter. But i get the message "Error, disabling serialEvent() for COM5
null"</p>

<pre><code>import processing.serial.*;
Serial port;
float currentAngle ;
float pitchacc ;
float pitch ;
int gyro = 1;
int accel = 2;
int xn = 0;
float yn1 = 250;
float yn2 = 250;
float yn3 = 250;
int xk = 0; 
void setup ()
{
  size (500,500);
  background (0);  
  port = new Serial ( this, "COM5", 9600);
  port.bufferUntil ('\n');
}
void draw ()
{ 
fill(255); 
stroke(255); 
line (xn, yn1, xk, currentAngle); 
line (xn, yn2, xk, pitchacc); 
line (xn, yn3, xk, pitch); 
if (xk &gt; 500) {  
background(0);  
xk=0;   
}      
xn=xk; 
yn1 = currentAngle;
yn2 = pitchacc;
yn3 = pitch;
xk++;
}

void serialEvent (Serial port)
{

  currentAngle = float(port.readStringUntil(gyro));
  pitchacc = float(port.readStringUntil(accel));
  pitch = float(port.readStringUntil('\n'));
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Problem with save data from serial port</title>
      <link>https://forum.processing.org/two/discussion/14931/problem-with-save-data-from-serial-port</link>
      <pubDate>Mon, 15 Feb 2016 18:23:54 +0000</pubDate>
      <dc:creator>Pedro_Henrique</dc:creator>
      <guid isPermaLink="false">14931@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys I'm new with Processing development and I having some problems. here's the issue: I'm using an Arduino to measuere temperature and just wanna to send it to Processing by serial communication and store it in to a .txt file.
I have already searched a solution in Processing tutorials and in this forum, but didn't find yet.
Any help is welcome!!
Here is my code (the comments are in Portuguese):</p>

<pre>
//Ler os dados da porta serial e salvar num arquivo .txt

import processing.serial.*;
import cc.arduino.*;

Serial portaCOM5; //Cria um objeto da classe Serial
String dados, COM5; //Dados em ASCII recebidos do Arduino
int val ;// Dados recebidos pela porta serial

//Banco de dados
PrintWriter arquivo; 

void setup ()
{
  size (200, 200);
  frameRate(10);   
  
     
   println(Serial.list ()); //Lista no Prompt de Comando todas as portas seriais disponíveis
   
   COM5 = Serial.list()[0]; //Recebe a porta USB escolhida
   portaCOM5= new Serial(this, "COM5", 9600); //taxa de transfarencia 9600bps
   portaCOM5.bufferUntil('\n');
      
        //Banco de dados:
   arquivo = createWriter("temperaturas"+"_"+month()+"-"+day()+"-"+year()+"_"+hour()+"-"+minute()+"-"+
            second()+".txt"); //cria um arquivo para armazenar as temperaturas
    
    arquivo.print("Monitoramento de Temperatura DHT11");
    arquivo.println();    
  
}

void draw()
{
  background (255); //Ajusta cor de fundo como branca
  
  }
   
void serialEvent(Serial portaCOM5)
{
  
     COM5= Serial.list()[0]; //Recebe a porta USB escolhida
       
      
  while (portaCOM5.available()&gt;0)
  {
     val = portaCOM5.readString();
     arquivo.println();
  }
         
  arquivo.flush(); // Writes the remaining data to the file
  arquivo.close(); // Finishes the file
         
}

</pre>

<p>PS: When I check the monitor serial from Arduino, the data are there, so I believe anything here is wrong.</p>

<p>Thanks!!!!</p>
]]></description>
   </item>
   <item>
      <title>move draw graph up by 100px</title>
      <link>https://forum.processing.org/two/discussion/14601/move-draw-graph-up-by-100px</link>
      <pubDate>Sun, 24 Jan 2016 16:09:15 +0000</pubDate>
      <dc:creator>zerocool5878</dc:creator>
      <guid isPermaLink="false">14601@/two/discussions</guid>
      <description><![CDATA[<p>Hi all
 I am trying to move this bar graph to the center of the window size while maintaining a 100px clear area for a scale, legend and titles to show thru from a background image. I managed to get the x start and end as well as the y sorted but i can't seem to locate an area to adjust where the graph starts in lower Y direction. any help you can offer would be greatly appreciated.</p>

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

Serial myPort;        // The serial port
int xPos = 100;         // horizontal position of the graph added to leave space on the left
float inByte = 0;

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

  // 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, "COM4", 115200);

  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');
  bg = loadImage("full.png");
  // set inital background:
  //background(255); //was 0 for black
   background(bg);
}
void draw () {
  // draw the line:
  stroke(0, 0, 0);  // was 127, 34, 255 use RGB to hex converter
  line(xPos, height, xPos, height - inByte);

  // at the edge of the screen, go back to the beginning:
  if (xPos &gt;= width-100) { //added -100 to leave room at right side
    xPos = 100; //reset x position once you get to end
    background(bg); //(255);// was 0 black you need to change both
  } 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 = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height-100); //minus 100 was added to leave space at top
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why does my scale not appear at the second screen?</title>
      <link>https://forum.processing.org/two/discussion/14484/why-does-my-scale-not-appear-at-the-second-screen</link>
      <pubDate>Fri, 15 Jan 2016 22:24:31 +0000</pubDate>
      <dc:creator>lupo99</dc:creator>
      <guid isPermaLink="false">14484@/two/discussions</guid>
      <description><![CDATA[<p>So I'm kinda new to Processing and java and had to programm a plotter, which gets data from an Arduino(connected to a Pirani Gauge), converts to pressure and displays it . When the Graph has ran once trough ( xPos &gt;= width) the programm clears the screen and should draw the scale new but it doesn't. I think I didn't get the Java Structure :D 
Thank you for your help and have a nice day :)</p>

<p>Here is the Code, you may need an Arduino sending println Strings to execute it</p>

<pre lang="java">
import processing.serial.*;
Serial myPort;       
int xPos = 1;         
float inByte = 0;
float printValue = 0;
PrintWriter output;
int d  =  day();    
int m  =  month();
int y  =  year();   
int h  =  hour();
int mi =  minute();
int value = 0;
int number = 55;
int axis = 0;
int incree = 1;
int increeax = 14;
String Tag     = str(d);
String Monat   = str(m);
String Jahr    = str(y);
String Stunde  = str(h);
String Minute  = str(mi);
String End     = (".txt");
String textValue = "";
void setup () {
fullScreen(); 
String[] Date = new String[6] ;
Date[0] = Tag   ;
Date[1] = Monat ;
Date[2] = Jahr  ; 
Date[3] = Stunde;
Date[4] = Minute;
Date[5] = End;
String DateData = join(Date, ",");
output = createWriter(DateData); 
printArray(Serial.list());
   
   myPort = new Serial(this, Serial.list()[0], 9600);
   myPort.bufferUntil('\n');
   
   background(0);
  
  }
void draw () {
  
  stroke(250, 0, 0);
  line(xPos, height, xPos, height - inByte);
  
  for (int i = 0; i &lt; 1370; i = i+14) {
       stroke(#FFFFFF);
       line(0, i, width, i); 
       textSize(15);
       text(number, 10, axis);
       number -= incree;
       axis += increeax;
      }
      
  output.println(printValue +" mBar" ); 
  printValue = map(inByte, 0, 1023, 0, 10);       //auf pressure ummappen, noch formel einsetzen
  fill(0);
  noStroke();
  rect(0, 0, width, 30);
  fill(#FFFFFF);
  text("Pressure:  " + printValue    + "     mBar", width -600, 25); 
  text("Pirani gauge pressure Analyzer Ver. 1.2  Copyright 2016 L.Ponzio", width - 1300, 25);
  text("Time: " + millis()+ " mSec", width -775, 25);
  text("mBar", width-1350, 25);
  
  if (xPos &gt;= width) {
    xPos = 30;
    background(0);
     } else {
       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);
  }
}
void keyPressed() {
  output.flush();  
  output.close();  
  exit();  
}
</pre>

<p>`</p>
]]></description>
   </item>
   <item>
      <title>Adding Radar sweep line to code.</title>
      <link>https://forum.processing.org/two/discussion/14452/adding-radar-sweep-line-to-code</link>
      <pubDate>Thu, 14 Jan 2016 06:32:36 +0000</pubDate>
      <dc:creator>herrmant</dc:creator>
      <guid isPermaLink="false">14452@/two/discussions</guid>
      <description><![CDATA[<p>I am building a weather radar based on Grook.nets code for an ultrasonic sensor, however, I am not using a ultrasonic sensor. I have modified the code in many ways... The radar currently can detect heavy rain/hail at about 40 mi. I would like to add a sweep line for effects on the screen. Could anyone help me out? I am attaching my code. Thank you.</p>

<pre><code>int cx; 
int cy; 
int r = 200;
int x = new int[100];
int y = new int[100];

import processing.serial.*;
Serial port;
Serial port2;
String data = "";
String Radius = "";
String Theta = "";
int index = 0;
float distance = 9000;
float angle = 10;
float pi = 22.0/7;

PImage img;



void setup() {
  size(600, 600);
  cx = width/2;
  cy = height/2;
  size(1000, 800);
  background(100);
  ellipse(500, 500, 1000, 1000);
  line(500, 0, 500, 1000);
  line(0, 500, 1000, 500);
  line(500, 500, 1000, 0);
  line(500, 500, 1, 1);
  img = loadImage("MAP3.png");
  tint(255, 1);
}
{



  port = new Serial(this, "COM3", 9600);
  port.bufferUntil('.');
}

void draw() {
  background (0);
  stroke(0, 200, 0); 
  float t = millis()/1500; 
  for (int i = 0; i &lt; 100; i++) {
    x[i] =(int) (cx+r*cos(t - i*0.01)); 
    y[i] =(int) (cy+r*sin(t - i*0.01));
    stroke(0, 200 - i * 2, 0); 
    line(cx, cy, x[i], y[i]);
  }


  image(img, 0, 0);
}

void serialEvent(Serial port)
{

  data = port.readStringUntil('.');
  data = data.substring(0, data.length() - 1);  
  index = data.indexOf(",");
  Radius = data.substring(0, index);
  Theta = data.substring (index+1, data.length());

  translate(500, 500);
  point (1, 1);

  distance = float(Radius); 
  angle = float(Theta) /180 * pi; 
  fill(10, 600, 20);
  ellipse(distance * cos(angle), -1 * distance * sin(angle), 40, 20);

  fill(98, 245, 31);


  noStroke();
  fill(8, 3); 
  rect(1000, 1, width, 1010);

  fill(98, 800, 31);
}
`
Thanks for any help. Initial code written by Grook.net. Modified by Tim Herrman.
</code></pre>

<p>Here is a link to an image showing what I want to do.</p>

<pre><code><a href="http://www.bing.com/images/search?q=Radar+Sweep&amp;view=detailv2&amp;&amp;id=22EB8F2D6B4A7022F64E3C9B07F1499647F2F8D1&amp;selectedIndex=23&amp;ccid=3s8XPcDD&amp;simid=608046625551091599&amp;thid=OIP.Mdecf173dc0c37904ea95e802d6180293o0&amp;ajaxhist=0" target="_blank" rel="nofollow">http://www.bing.com/images/search?q=Radar+Sweep&amp;view=detailv2&amp;&amp;id=22EB8F2D6B4A7022F64E3C9B07F1499647F2F8D1&amp;selectedIndex=23&amp;ccid=3s8XPcDD&amp;simid=608046625551091599&amp;thid=OIP.Mdecf173dc0c37904ea95e802d6180293o0&amp;ajaxhist=0</a>
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to transform String in float :  float value = float(cm); ? Help</title>
      <link>https://forum.processing.org/two/discussion/14085/how-to-transform-string-in-float-float-value-float-cm-help</link>
      <pubDate>Sun, 20 Dec 2015 13:27:47 +0000</pubDate>
      <dc:creator>dmada</dc:creator>
      <guid isPermaLink="false">14085@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>Currently I make a project for learn how to discuss between sensor and processing.
So Processing read correctly the port of arduino ( I can see the value with processing)</p>

<p>My problem it's a cannot use this data for make something ( example I want to hide or show like influenced the opacity of an picture). For influenced the opacity I use a white rect but maybe is not a good idea.</p>

<p>Because ( maybe) I've string informations and for make a "if" I use a float .
I search differents things but i'm lost with the differents method to are not very clear. 
I search to transform "cm" in float var1 for use my if. After I thinking to make a map for transform the data.</p>

<pre><code>        // the code with proximity sensor and "cm" like string value. 


        import cc.arduino.*;
        import org.firmata.*;
        import processing.serial.*;

        Serial myPort;   
        String cm;
        float var1;
         PImage fonds;


        void setup() {

           size(displayWidth, displayHeight); //full screen
          println(Serial.list());
          myPort = new Serial(this, Serial.list()[6], 9600);  // go to read the COM of arduino
         myPort.bufferUntil('\n');
          fonds = loadImage("testu.jpg");
           image(fonds, 0, 0,displayWidth,displayHeight); 

        }

        void draw() {


        while (myPort.available() &gt; 0) { //Continue usb serial
            String cm = myPort.readStringUntil('\n'); // Read port analog
            if(cm!=null) {
             cm = trim(cm);

              float var1 = float(cm); // The problem is here how to transform this value

               var1 = map (var1, 0, 700, 0, 255);
            println(cm); // affichage
            println(var1);

            }                       
        }
        if (var1 &gt; 100){                 // currently he don't read this part
         noStroke();
         fill(255,0);
        rect(0, 0,displayWidth,displayHeight);
        smooth();
        }

        else { 
           noStroke();
         fill(255,10);
        rect(0, 0,displayWidth,displayHeight);
        smooth();
        } 

        }
</code></pre>

<p>Sorry for my english if i make some mistake.
Thank's 
Kinds regards</p>
]]></description>
   </item>
   <item>
      <title>How to draw a complete color wheel?</title>
      <link>https://forum.processing.org/two/discussion/14032/how-to-draw-a-complete-color-wheel</link>
      <pubDate>Wed, 16 Dec 2015 22:27:03 +0000</pubDate>
      <dc:creator>Gears</dc:creator>
      <guid isPermaLink="false">14032@/two/discussions</guid>
      <description><![CDATA[<p>Hello people,</p>

<p>I'm trying to create a program that I can use to control the LED strips inside my PC using Arduino. I currently have communication and a lot of other parts working already, but I am stuck on a small problem.</p>

<p>I am able to draw a color wheel or rectangle in this case that <strong>should</strong> represent all colors available. The program looks at the value under the mouse while it is pressed, and sends this to the Arduino. The problem I am having is that the colors nearest to the edge are not picked up as pure red (255,0,0), green or blue. The closest value I can get is: (255,32,32).</p>

<p>What I have tried so far is changing the size of the rectangle to exclude the missing colors being rendered off-screen. I have found that the code reading the color value under the cursor is correct - I did this by drawing a plain pure red rectangle in the corner, which returned the correct value (255,0,0). I also found that simply subtracting 32 from the values is incorrect, as on pure white you will find the value to be (223,223,223).</p>

<p>This causes significant problems with my LEDs, as a value of 32 on the PWM pin will light the corresponding color up by quite a bit because of the non-linear relationship between LED volt and brightness.</p>

<p>So to reiterate my question: how do I draw a color circle or rectangle from which I can get 100% red, blue and green as well?</p>

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

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

Serial myPort;    // The serial port
String inString;  // Input string from serial port
int lf = 10;      // ASCII linefeed 
int[] rgb = new int[3];
PImage m;

void setup(){
  size(400,400);
  frameRate(120);
  smooth(4);
  ellipseMode(CENTER);
  background(255);

  colorMode(HSB, 400);
  for (int i = 0; i &lt; 400; i++) {
    for (int j = 0; j &lt; 400; j++) {
      stroke(i, j, 400);
      point(i, j);
    }
  }
  m=get();

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

void draw(){
  image(m,0,0);
  if(mousePressed){
    color c = get(mouseX,mouseY);
    fill(c);
    stroke(0);
    ellipse(mouseX,mouseY,30,30);
    rgb[0] = c &gt;&gt; 16 &amp; 0xFF;
    rgb[1] = c &gt;&gt; 8 &amp; 0xFF;
    rgb[2] = c &amp; 0xFF;

    fill(0);
    text(rgb[0], 10,70);
    text(rgb[1], 10,90);
    text(rgb[2], 10,110);

    String test = ",";
    test += str(rgb[0]);
    test += "+";
    test += str(rgb[1]);
    test += "+";
    test += str(rgb[2]);
    test += "\n";

    myPort.write(test);
  }
  fill(0);
  text("Received: " + inString, 10,50);
}

void serialEvent(Serial p) { 
  inString = p.readString(); 
} 
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to verify the Serial.list()</title>
      <link>https://forum.processing.org/two/discussion/13849/how-to-verify-the-serial-list</link>
      <pubDate>Wed, 09 Dec 2015 00:36:46 +0000</pubDate>
      <dc:creator>salvatore_94</dc:creator>
      <guid isPermaLink="false">13849@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,
i'm trying to figure out how can i know what are the ports in the serial array.
I'm using this code:</p>

<pre><code>    while(i&lt;Serial.list().length&amp;&amp;!trovato){
              if((Serial.list()[i]=="COM1")||(Serial.list()[i]=="COM2")||(Serial.list()[i]=="COM3")||(Serial.list()[i]=="COM4")||(Serial.list()[i]=="COM5"))
</code></pre>

<p>The if condition is always false, but if i print the Serial.list() array i can see that i have a COM4 and the lenght is 1.
I need to use that because i don't know if arduino will be connected on another COM on an other PC.</p>

<p>The full if is</p>

<pre><code>        int i=0;
                while(i&lt;Serial.list().length&amp;&amp;!trovato){
                  if((Serial.list()[i]=="COM1")||(Serial.list()[i]=="COM2")||(Serial.list()[i]=="COM3")||(Serial.list()[i]=="COM4")||(Serial.list()[i]=="COM5")){
                    pos=i;
                    trovato=true;
                  }
                  else
                  i++;
                }
                if(trovato){
                  porta= new Serial(this, Serial.list()[pos], 9600);
                  porta_connessa=true;
                }
                else
                  porta_connessa=false;
</code></pre>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>My sketch reads one pixel from arduino, then gives me an ArrayIndexOutOfBoundsException</title>
      <link>https://forum.processing.org/two/discussion/13794/my-sketch-reads-one-pixel-from-arduino-then-gives-me-an-arrayindexoutofboundsexception</link>
      <pubDate>Sat, 05 Dec 2015 19:22:01 +0000</pubDate>
      <dc:creator>Dirruk</dc:creator>
      <guid isPermaLink="false">13794@/two/discussions</guid>
      <description><![CDATA[<p>Dear Forum,</p>

<p>I'm building a drawbot that draws bitmaps. I'm almost there -thanks to the good people here-, but I can't get my head around this issue here.</p>

<p>I have a Processing sketch that can parse coordinates from a string from my arduino, display the corresponding pixel on screen and send the brightness of that pixel back to the arduino. Then I have an arduino code that can move to the next pixel and send its location coordinates as a string.</p>

<p>This seems to work, but only for one pixel. Then processing sends me and ArrayIndexOutOfBoundsException. I guess I need to flush a string somewhere. But I don't know which one. The debuggerer somehow gets stuck on my sketch too. So some advice would be really helpful.</p>

<p>Here's the Processing sketch:</p>

<pre><code>    import processing.serial.*; //import the Serial library

    Serial myPort;  //the Serial port object
    String strIn = "";  //Declare a string with name strIn, this will store the coordinates received from the arduino
    String strOut = "";  //Declare a string with name strOut, this will store the coordinates and corrseponding geryvalue of a pixel in the bitmap.
    String portName = "";  //apparently this is necessary
    String coordinates;
    int locX= 0;
    int locY= 0;

    PImage img;

    void setup()
    {

      size(182, 262);  //This is the size of the canvas and the range of the printer //&lt;&gt;//
      // Make a new instance of a PImage by loading an image file
      img = loadImage("parel.bmp");
      tint(255, 100);
      image (img, 0, 0);
      String portName = Serial.list()[0];
      myPort = new Serial(this, portName, 9600);
    }


    void draw()
    { 
      if (myPort.available() &gt; 0)                     // If data is available,
      {
        strIn = myPort.readStringUntil('\n');         // read it and store it in a string called strIn
        String[] coordinates = split(strIn, ",");    
        //Cut the strIn string at the comma into two strings called coordinates. 
        //We expect a message coming in something like "XXX,YYY"
        int locX = int(trim(coordinates[0]));        //This says that the first string is an integer called LocX
        int locY = int(trim(coordinates[1]));       //This says that the next string is an integer called LocX
        color pix = img.get(locX, locY);             //look up the colour of the requested pixel
        stroke(pix);                                 //show the pixel on the canvas on screen
        point(locX, locY);
        int Bright = round(brightness(pix));        //sending pix will send a large negative string, so we will just send the brightness
        strOut = locX + "," + locY + "," + Bright + "L" + "\n";  //put all the needed values into a string called strOut
        myPort.write(strOut);                                    //send it over serial port to the arduino to parse
        }
    }
</code></pre>

<p>And here's the arduino sketch:</p>

<pre><code>// Jerry Wirerammer lives!

unsigned int xPos ;           //this integer sets the X position of the robot
unsigned int yPos   ;         //this integer sets the Y position of the robot
unsigned int xGoal  ;        //this integer sets the X location of the pixel where the mothership thinks the robot is. If the Robot is in position, it can put a dot.
unsigned int yGoal   ;       //this integer sets the X location of the pixel where the mothership thinks the robot is. If the Robot is in position, it can put a dot.
unsigned int GreyValue ;
char val;
int CanvasWidth = 182;
int CanvasHeight = 263;
String received ;

void setup() {

  Serial.begin(9600);                             //Serial communication, we are using it


  goHome();        //move to the 0,0 position.
}



void loop() {


  Serial.print(xPos);
  Serial.print(",");
  Serial.println(yPos);


  if ( Serial.available() ) // if data is available to read
  {
    val = Serial.read();    // read it and store it in 'val'
    if ( val != 'L' ) {     // if not an 'L'
      received += val;          // add it to the received string
    }

    else {
      // if 'L' was received (our designated termination char)
      //Look for the location of the first comma
      int commaIndex = received.indexOf(',');
      //  Search for the next comma just after the first
      int secondCommaIndex = received.indexOf(',', commaIndex + 1);

      String firstValue = received.substring(0, commaIndex);  //the first series of characters before the first comma
      String secondValue = received.substring(commaIndex + 1, secondCommaIndex); //the next series of characters between the first and second comma
      String thirdValue = received.substring(secondCommaIndex); //the final series of characters before the L that we didn't add to the "received" string

      xGoal = firstValue.toInt();
      yGoal = secondValue.toInt();
      GreyValue = thirdValue.toInt();

/*    debugging purposes only:
      Serial.print("received:");
      Serial.println(received);
      Serial.print("xGoal =");
      Serial.println(xGoal);
      Serial.print("yGoal =");
      Serial.println(yGoal);
      Serial.print("xPos =");
      Serial.println(xPos);
      Serial.print("yPos =");
      Serial.println(yPos);
*/

      received = "";                // Flush the string so we can receive new data
    }
  }
  else {
    delay (1000); // wait a bit and try again
  }


  if (xGoal == xPos) {
    if (yGoal == yPos) {
      MoveOn();
    }
  }
}


void MoveOn() //this subroutine tells the robot how to move to the next position.
{
  if (xPos != CanvasWidth) {   //if we are not at the end of the x axis
    xPos = xPos + 1;          //and adjust x position by increasing by one
  }
  else if (yPos != CanvasHeight) { //if we are not at the end of the y axis
    xPos = 0;           //and adjust x position to its starting value
    yPos = yPos + 1;                  //and adjust y position by increasing by one
  }
  else {
    delay(1);                       //Do nothing. This will make the robot print the last pixel over and over again.
  }
}




void goHome() //this subroutine tells the robot how to move to position 0,0
{
  while (xPos != 0) {         //if we are not x position 0
    xPos = xPos - 1;          //and adjust x position by increasing by one
    //this will repeat until we are at position x=0
  }

  while (yPos != 0) {         //if we are not x position 0
    yPos = yPos - 1;          //and adjust x position by increasing by one
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Create a graph (live-feed or after data collection) of sensor data from an Arduino serial port</title>
      <link>https://forum.processing.org/two/discussion/13679/create-a-graph-live-feed-or-after-data-collection-of-sensor-data-from-an-arduino-serial-port</link>
      <pubDate>Fri, 27 Nov 2015 02:51:52 +0000</pubDate>
      <dc:creator>SamCE</dc:creator>
      <guid isPermaLink="false">13679@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have a code which takes data from 2 sensors that is incoming through the serial port of an Arduino and outputs it into a .csv file. This data is received as a float of the format "y, x" which is then delimited/split by the use of the comma and put into an array. The "y" data is a depth in mm measurement and the "x" is a correlating distance moved in mm.</p>

<p>I have been trying to get the code to output either a live-feed line graph or a line graph after the file is written with data "x" on the x-axis and "y" on the y-axis.</p>

<p>My experience with Processing is very limited and I have tried with no luck to adapt pretty much all of the examples I could find on the various forums and tutorials. Any help that could be offered would be very gratefully received, I don't mind if the solution is live-feed or after the .csv is written just having a graph out would be great.</p>

<p>Below I have shown a plot I did manually in excel to show the kind of output I am trying to get as well as the code I have got already which I have annotated on to try to make understanding my process as pain-free as possible.</p>

<p><img src="" alt="" /><img src="https://forum.processing.org/two/uploads/imageupload/807/GNM4FELYYQN3.jpg" alt="Output_Example" title="Output_Example" /></p>

<pre><code>import processing.serial.*;
Serial myPort; //creates a software serial port
Table dataTable; //table where values are stored
Table table; 

int numReadings = 500; //number of readings from sensors until .csv file is written
int readingCounter = 0; //counts each reading to compare to numReadings. 

String val;
String fileName;

void setup()
{
  String portName = Serial.list()[0]; //defines COM port

  myPort = new Serial(this, portName, 9600); //port setup, 9600 baud rate

  table = new Table();

  //table.addColumn("id"); //id number for incoming data starting

  //the following adds columns for time. (currently not used)
  //table.addColumn("year");
  //table.addColumn("month");
  //table.addColumn("day");
  //table.addColumn("hour");
  //table.addColumn("minute");
  //table.addColumn("second");
  //table.addColumn("milliseconds");

  //the following adds columns for each sensor set. Change for sensors and keep in correct order.
  table.addColumn("Depth");
  table.addColumn("Width");

}

void serialEvent(Serial myPort){

  try {
  val = myPort.readStringUntil('\n'); //The newline separator separates each Arduino loop and so collection of data. 
  if (val!= null) { //Verifies reading
    val = trim(val); //gets rid of any whitespace or Unicode nonbreakable space
    println(val); //Shows received data
    float sensorVals[] = float(split(val, ',')); //parses the packet from Arduino and places the float values into the sensorVals array.

    TableRow newRow = table.addRow(); //adds a row for new reading
    //following not used at present
    //newRow.setInt("id", table.lastRowIndex());//record an id for readings

    //record time stamp
    //newRow.setInt("year", year());
    //newRow.setInt("month", month());
    //newRow.setInt("day", day());
    //newRow.setInt("hour", hour());
    //newRow.setInt("minute", minute());
    //newRow.setInt("second", second());

    //record sensor information. Make sure same as sensor column names.
    newRow.setFloat("Depth", sensorVals[0]);
    newRow.setFloat("Width", sensorVals[1]);

    readingCounter++; //writes file every numReadings reading cycles

    //saves the table as a csv in the same folder as the sketch every numReadings. 
    if (readingCounter % numReadings ==0)//checks number of readings is correct
    {
      fileName = str(year()) + str(month()) + str(day()) + str(table.lastRowIndex()); //filename is of the form year+month+day+readingCounter
      saveTable(table, fileName + ".csv"); //saves the data as a .csv
    }
   }
  }
  catch(RuntimeException e) {//catches errors
    e.printStackTrace();
  }

}

void draw () {

}
</code></pre>

<p>Sam</p>
]]></description>
   </item>
   <item>
      <title>Real time graph plotting - My processing graph goes wrong side</title>
      <link>https://forum.processing.org/two/discussion/8184/real-time-graph-plotting-my-processing-graph-goes-wrong-side</link>
      <pubDate>Sun, 16 Nov 2014 09:11:23 +0000</pubDate>
      <dc:creator>Stonegaze</dc:creator>
      <guid isPermaLink="false">8184@/two/discussions</guid>
      <description><![CDATA[<p>Hi.</p>

<p>I'm trying to make a pulse oximeter with Arduino UNO.</p>

<p>I've made basic electronic circuit using SFH-4557(850nm) LED, MTE6066N1-UR (650nm) LED, and OPT101P Photosensor. I think it works well.</p>

<p>Objective: The arduino sends two data(650nm, 850nm sensor values) respectively, and Processing receives these data and assign to different array variables and plotting...;  (Sorry for poor English..)</p>

<p>But when I using processing 2.2.1, I've found out that my graph goes from right to left, and it looks like blinking boxes!!...
 I've used <a rel="nofollow" href="http://arduino.cc/en/pmwiki.php?n=Tutorial/Graph">Tom Igoe's code</a>  in arduino homepage. I just modified it a little..</p>

<p>My code are here.. What's wrong with my code? Is this a frame rate problem? I don't understand what problem makes me crazy...</p>

<p>Please help..</p>

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

Serial myPort;
int xPos = 1;

PFont f;

//Values of seperate LEDs
float[] S850Val = new float[600];
float[] S650Val = new float[600];

void setup() {
  size(600, 600);
  frameRate(60);
  println(Serial.list());

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

  f = createFont("Arial", 32, true);
}


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

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

    float inByte = float(inString);

    inByte = map(inByte, 0, 1023, 0, 300);


    //assign Sensor 850nm, Sensor650
    for (int i = 0; i &lt; 600; i++){
      if (inByte &lt; 200.0) {
        S850Val[i] = inByte;
      } else {
        S650Val[i] = inByte;
      }
    }


    //drawing both sensor's data
    for (int j = 0; j &lt; 600; j++){
      if(xPos &gt;= width){
        xPos = 0;
        background(0);
      }else{
        xPos++;}
      //Printing legend..  
      textFont(f);
      fill(255);
      text("650nm", 10, 32);
      text("850nm", 10, 332);
      //Drawing graph     
      stroke(255);
      line(xPos, 300, xPos, (300 - S650Val[j]) + 100);
      line(xPos, 600, xPos, (600 - (S850Val[j] * 10) - 100));
      //Test print (Temporary serial output)
      println(S650Val[j]);
      println(S850Val[j]);     
    }    
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>collecting, averaging &amp; ignoring duplicate serial data</title>
      <link>https://forum.processing.org/two/discussion/13374/collecting-averaging-ignoring-duplicate-serial-data</link>
      <pubDate>Mon, 02 Nov 2015 22:23:20 +0000</pubDate>
      <dc:creator>rossdickinson</dc:creator>
      <guid isPermaLink="false">13374@/two/discussions</guid>
      <description><![CDATA[<p>Hey, I'm trying to receive data from the serial port, collect a sample group ('numReadings'), average it ('average'), and print it to screen only if the new average ('average') isn't equal to the old average ('previousAverage').</p>

<p>Below I have some really horrible code, trying to illustrate the idea, but i'm having trouble pulling it all together and amn't 100% if this is the best way to do it.</p>

<p>Would really appreciate if anyone was able to offer advice!</p>

<p>Cheers,</p>

<p>Ross</p>

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

Serial myPort;
int numReadings = 512;
int readIndex = 0;
int total = 0;
int average = 0;
int previousAverage = 0;
int[] readings = new int[numReadings];

void setup() {

  size(640, 640);
  background(30);
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('n');
}

void draw() {
}

void serialEvent (Serial MyPort) {

    for (int thisReading = 0; thisReading &lt; numReadings; thisReading++) {
    readings[thisReading] = 0;
  }

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

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

  total = total - readings[readIndex];
  readings[readIndex] = inString;
  total = total + readings[readIndex];
  readIndex = readIndex + 1;


  if (readIndex &gt;= numReadings) {
  readIndex = 0;
  }

average = total / numReadings;

if (average != previousAverage) {
println(average);
}
  previousAverage = average;
}
</code></pre>

<p>Processing 2.2.1 (i need to update i know)
Windows 8</p>
]]></description>
   </item>
   <item>
      <title>Arduino+Processing Problem: ArrayIndexOutOfBounds</title>
      <link>https://forum.processing.org/two/discussion/13110/arduino-processing-problem-arrayindexoutofbounds</link>
      <pubDate>Mon, 19 Oct 2015 08:51:17 +0000</pubDate>
      <dc:creator>Moonbrain</dc:creator>
      <guid isPermaLink="false">13110@/two/discussions</guid>
      <description><![CDATA[<p>Hi Everyone, i've been working on a little program combining arduino and processing aiming at generating visuals from movement ( gyroscope + vibration sensor).</p>

<p>So far I tested both the gyroscope and the vibration sensor separately and it worked just fine. 
Since I've tried to combine them i've been getting this error message:  <strong>ArrayIndexOutOfBoundsException: 1</strong> and the line 53: <strong>float  roty = (sensors[1]*10);</strong> is highlighted at the same time</p>

<p>I assume there is a problem with myString content, or I guess with the string access and my sensors declaration but I can't figure out what to do.
I've been learning code for a very short time, please have mercy on my inaccuracies ^^<br />
(i'm french so comments are mostly in french,let me know if you need me to explain myself)
Thank you so much for your help !!!</p>

<pre><code>    import glitchP5.*; //import Glitch P5
    String portName = "/dev/cu.usbmodem1421"; 
    import processing.serial.*;
    String serial; 
    Serial myPort;
    int linefeed = 10; 
    int numSensors = 3; 
    float[] sensors;
    float[] pSensors;
    float bornexinf=0; 
    float bornexsup=0;
    float borneyinf=0; 
    float borneysup=0; 
    float rotxold=0; 
    float rotyold=0; 
    // vibration
    int end = 10;    //Le nombre 10 en ASCII pour linefeed marquant la fin du serial.println
    GlitchP5 glitchP5; // declare an instance of GlitchP5. only one is needed
    int j=0; //variable d'incrémentation carré dans carré
    int max=1; //nombre d'itération, soit le nb de carrés dans le carré
    int longueur=10; // longueur du carré 
    int largeur=10; //largeur du carré
    float value=0; //variable pour la rotation
    float mouseXold=displayWidth/2;
    float mouseYold=displayHeight/2;

    void setup() {

     size(displayWidth, displayHeight);
     background (255);
     smooth();

      myPort = new Serial(this, portName, 9600);
      myPort.bufferUntil(linefeed);
      serial = myPort.readStringUntil(end); // fonction qui lit la chaine de caractères depuis le port série jusqu'à println et ensuite assigne string à notre variable qui appelle serial
      serial = null; // initialisation de serial
     glitchP5 = new GlitchP5(this);
    }


    void draw() {

      while (myPort.available() &gt; 0) { //tant qu'il n'y a pas de données provenant du port on lit l'entrée série
        serial = myPort.readStringUntil(end);
      }
        if (serial != null) {  
          String[] a = split(serial, ','); //on créé un tableau qui définit une chaine séparée par des virgules. 
          println(a[0]); //on affiche la première valeur du tableau
        }

      if((pSensors != null)&amp;&amp;(sensors != null)) { 
        float  rotx = (sensors[0]*10);
        float  roty = (sensors[1]*10);
        float  rotz = (sensors[2]*PI)/180;

    strokeWeight(1);
    noFill(); 
    stroke(random(255),random(255),random(255));
    translate(500,150);
    rectMode(CENTER);


    for(j=0;j&lt;max;j++){
        longueur=longueur+1; 
        largeur=largeur+1; 
        translate(width/2, height/2);
        rotate(value);
        translate(-width/2, -height/2);
        rect(rotx,roty,longueur,largeur); 
        redraw();
        bornexinf=rotxold-10; 
        bornexsup=rotxold+10;
        borneyinf=rotyold-10; 
        borneysup=rotyold+10; 
        if(bornexinf&gt;rotx || rotx&gt;bornexsup || borneyinf&gt;roty || roty&gt;borneysup){
        longueur=5;
        largeur=5;
        }
        rotxold=rotx;
        rotyold=roty;
    }
      }
     glitchP5.run();
    }


    void serialEvent(Serial myPort) {


      String myString = myPort.readStringUntil(linefeed);
      if (myString != null) {
              myString = trim(myString);
              pSensors = sensors;
              sensors = float(split(myString, ','));

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

    void mousePressed() //===&gt; Will be triggered by the vibration sensor : if =0 do nothing; if =1 glitch; //
    {
     glitchP5.glitch(mouseX, mouseY, 200, 400, 200, 60, 120, 10.0f, 20, 1);
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can I convert groups of incoming bytes received via serial to a singel int.</title>
      <link>https://forum.processing.org/two/discussion/12769/how-can-i-convert-groups-of-incoming-bytes-received-via-serial-to-a-singel-int</link>
      <pubDate>Thu, 01 Oct 2015 12:25:48 +0000</pubDate>
      <dc:creator>donuan</dc:creator>
      <guid isPermaLink="false">12769@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I am using processing to communicate via serial with a fingerprint sensor (GT-511C3) and the messages it sends looks something like this: 55-AA-01-00-0F-10-00-00-31-00-50-01.</p>

<p>as these are sent separately and constantly I cannot in this state listen for a specific byte changing (e.g. the 0F changing to 00) so I would like to convert these sets of bytes to ints so that I can use them to trigger specific events.</p>

<p>Any idea of how I would go about to do that would be much appreciated.</p>

<p>here is the code Im using to receive them:</p>

<p>void serialEvent(Serial p)
{
  byte rx_byte;</p>

<p>while (p.available() &gt; 0) {
    // get a single character from the serial port
    rx_byte = (byte)serial_port.readChar();
    println(hex(rx_byte));
  }
}</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>How to avoid multiple keypresses from Fruit Piano sensors (Arduino USB HID)</title>
      <link>https://forum.processing.org/two/discussion/13225/how-to-avoid-multiple-keypresses-from-fruit-piano-sensors-arduino-usb-hid</link>
      <pubDate>Sat, 24 Oct 2015 13:31:08 +0000</pubDate>
      <dc:creator>dekwaedsteniet</dc:creator>
      <guid isPermaLink="false">13225@/two/discussions</guid>
      <description><![CDATA[<p>I'm using Capacitive Sensors to measure input from fruit to trigger events in Processing (like a sound, or in this case a video). I don't want to delay the Arduino program, so it keeps scanning for input. The Arduino sens keypresses (as a USB HID device) to the pc, so I can detect keypresses in Processing. The problem is that often the Arduino is scanning so fast that it sends multiple Keypresses, so the video keeps triggering.</p>

<p>I want to solve this in Processing, so that I don't have to use a delay in the Arduino code. My question is, how do I integrate this type of code:</p>

<pre><code>int sX, sY, sT;

void setup(){
  size(200,200);
}

void draw(){
  background(0);
  if( mousePressed ){
    sX = mouseX;
    sY = mouseY;
    sT = millis() + 2000;
  }
  if( millis() &gt; sT &amp;&amp; millis() &lt; sT + 2000 ){
    fill(255,0,0);
    rect(sX-5, sY-5, 10, 10);
  }
}
</code></pre>

<p>into this:</p>

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


int maxmyMovies = 5; 
int myMoviesIndex = 0; 
Movie[] myMovies = new Movie[maxmyMovies];

void setup() {

  size(1280, 720);
  for (int i = 0; i &lt; myMovies.length; i ++ ) {
    myMovies[i] = new Movie(this, i + ".mp4");
    myMovies[i].loop();
  }
}

void movieEvent(Movie myMovies) {

  myMovies.read();
}

void draw() {
  image(myMovies[myMoviesIndex], 0, 0, 1280, 720); // Displaying one image
}

void keyPressed() {

  if (key=='a') {
    myMovies[myMoviesIndex].pause();
    myMovies[myMoviesIndex].jump(0.0);
    myMoviesIndex = 1;
    myMovies[myMoviesIndex].play();
  } 
  if (key=='b') {
    myMovies[myMoviesIndex].pause();
    myMovies[myMoviesIndex].jump(0.0);
    myMoviesIndex = 2;
    myMovies[myMoviesIndex].play();
  } 
  if (key=='c') {
    myMovies[myMoviesIndex].pause();
    myMovies[myMoviesIndex].jump(0.0);
    myMoviesIndex = 3;
    myMovies[myMoviesIndex].play();
  } 
  if (key=='d') {
    myMovies[myMoviesIndex].pause();
    myMovies[myMoviesIndex].jump(0.0);
    myMoviesIndex = 4;
    myMovies[myMoviesIndex].play();
  }
}
</code></pre>

<p>I have to scan for almost the entire alphabet, so the code is getting very messy. Is there also a way of simplifying this? Thanks in advance for your help.</p>
]]></description>
   </item>
   <item>
      <title>How to load/save data from serial port to a .txt file?</title>
      <link>https://forum.processing.org/two/discussion/13077/how-to-load-save-data-from-serial-port-to-a-txt-file</link>
      <pubDate>Sat, 17 Oct 2015 22:23:26 +0000</pubDate>
      <dc:creator>elunicotomas</dc:creator>
      <guid isPermaLink="false">13077@/two/discussions</guid>
      <description><![CDATA[<p>Hello there,</p>

<p>Last week thanks to the help of <a rel="nofollow" href="http://forum.processing.org/two/discussion/12920/problem-reading-a-rfid-reader">GoToLoop</a> I manage to get a RFIP reader to work. And eventually I made this code that shows a picture for a a few second if the RFID reader reads the correct card.</p>

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

static final String COMPARADOR = "4500B8C02A17";
static final String DEPOSITO = "Deposito $50";
static final String SALDO = "Saldo en 0";

String mensaje = "Texto inicial";

int tiempo;
int espera = 5000;

PImage imagen;

int contador = 1;

void setup() {
  size(900, 600);
  frame.setBackground(new java.awt.Color(0, 0, 0));
  imagen = loadImage("1.jpg");

  String[] portas = Serial.list();
  printArray(portas);

  new Serial(this, portas[0], 9600).bufferUntil(ENTER);

  tiempo = millis();
}

void draw () {


  if (COMPARADOR.equals(mensaje)) {
    imageMode(CENTER);
    image(imagen, width/2, height/2);
    if (millis() - tiempo &gt;= espera) {
      mensaje = SALDO;
      tiempo = millis();
      contador++;
    }
  } else {
    background(0);
  }



  println(mensaje);
  print("Pasada #: ");
  println(contador);
  print("Tiempo: ");
  println(tiempo);
}

void serialEvent(Serial s) {
  mensaje = s.readString().trim();
}
</code></pre>

<p>The thing is that there will be many cards and what I want is that each card can be used only once. So If a card is read for the first time, the image is displayed. If the same card is read later nothing happens.</p>

<p>So far I read about saving/loading data from a .txt file, and I guess this is the easiest way. To store (in a .txt file) the cards that have been read,  and to check (in the same .txt file) every time a new card is read and if has been already read nothing happens, and if it is the first time is read the image is displayed.</p>

<p>I am trying but with no success, any ideas?</p>

<p>Thanks!</p>
]]></description>
   </item>
   </channel>
</rss>