<?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 analogread() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=analogread%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:43:46 +0000</pubDate>
         <description>Tagged with analogread() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedanalogread%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Processing (image display) via Arduino ultrasonic sensor</title>
      <link>https://forum.processing.org/two/discussion/28055/processing-image-display-via-arduino-ultrasonic-sensor</link>
      <pubDate>Thu, 14 Jun 2018 12:33:26 +0000</pubDate>
      <dc:creator>komats</dc:creator>
      <guid isPermaLink="false">28055@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I am just starting to explore posibilities to make something work in processing via arduino (sensors). On school exhibition I want to make a <strong>picture display that shows one image at the time on the wall (with a projector), depending how close or far person is located from distance sensor.</strong>
This is a sketch of what I am thinking about:<img src="https://forum.processing.org/two/uploads/imageupload/088/QJY2PU3L5TTS.jpg" alt="example" title="example" />
To see if it really works, I explored some tutorials that explains how to connect Arduino input with Processing. Currently, I have these codes in both programs:
<strong>for Arduino:</strong></p>

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

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

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

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

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

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

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

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

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

void draw(){

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

}

void serialEvent(Serial myPort){

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

}
</code></pre>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<p>The values:</p>

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

<p>and the graph:</p>

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

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

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

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

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

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

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

float fValue;
float lastfValue;
boolean newVal = false;

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

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

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

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

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

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

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>SOLVED //Save data from serial Arduino to txt using Processing</title>
      <link>https://forum.processing.org/two/discussion/25251/solved-save-data-from-serial-arduino-to-txt-using-processing</link>
      <pubDate>Tue, 28 Nov 2017 15:00:28 +0000</pubDate>
      <dc:creator>DeDaymar</dc:creator>
      <guid isPermaLink="false">25251@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys,</p>

<p>I'm working on a program that saves data from my potentiometer to a txt file. The idea is that I have my potentiometer on analog A0 and every second the value of the analog port has to be saved in Processing in a file. After a minute, the data has to be saved in another file. So I actually have to build something that saves 60 values per minute. And added to that, the data in the file has to have the actual time behind it.</p>

<p>For Arduino I have to use Firmata.</p>

<p>My processing code for now :</p>

<pre><code>import processing.serial.*;
import cc.arduino.*;          //this is all double, but I don't know which to use
Arduino arduino;
Serial pot;

void setup() {
//println(Serial.list());
//pot = new Serial(this, Serial.list()[0], 9600);    //should I use Serial or Arduino?


println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
PrintWriter output;
output = createWriter("data.txt");
output.println(arduino.analogRead(0));  //in the file it only prints 0
output.flush();
output.close();
}

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

<p>Yes, I know this code is far from finished. That's why I have come here, for your help. 
I put some things in the code, I hope you can answer those questions.
And I need some help with creating a new file after 1 minute.</p>
]]></description>
   </item>
   <item>
      <title>Filtering heart rate sensor</title>
      <link>https://forum.processing.org/two/discussion/23513/filtering-heart-rate-sensor</link>
      <pubDate>Tue, 18 Jul 2017 22:41:33 +0000</pubDate>
      <dc:creator>kripkus</dc:creator>
      <guid isPermaLink="false">23513@/two/discussions</guid>
      <description><![CDATA[<p>Hello!
I'm working on project where I'm trying to make music from my real time heart beat
I'm using ad8232 heart monitor and Arduino UNO
Here is my bare bones code:</p>

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

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

void setup() {
  size(500, 500);
  file = new SoundFile(this, "KICK011F.wav");
  // Prints out the available serial ports.
  println(Arduino.list());

  arduino = new Arduino(this, Arduino.list()[1], 57600);
}

void draw() {
  background(0);

  if (arduino.analogRead(1)&lt;600) {
    file.play();
  }
</code></pre>

<p>I would like to somehow filter the signal and only play one sound on each heart beat. 
For now it works fine, but sometimes there are multiple sounds for one heart beat.
It should somehow see each beat and play the sound once. 
I'm guessing it could be done by setting a minimal distance between two sounds and choosing the highest value for each beat.
I doesn't work if I just set a global theshold, because sometimes the highest value for one beat is lower then second highest in other.</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Processing not reacting properly to arduino via firmata</title>
      <link>https://forum.processing.org/two/discussion/22376/processing-not-reacting-properly-to-arduino-via-firmata</link>
      <pubDate>Thu, 04 May 2017 00:01:46 +0000</pubDate>
      <dc:creator>ailisg</dc:creator>
      <guid isPermaLink="false">22376@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I'm using an arduino uploaded with firmata. I have a potentiometer hooked up and as the user turns the potentiometer, depending on the value they land on, a certain video will play. So if they turn it up more a different video will play etc.
What's happening is I have to turn the potentiometer to a value, and then turn it all the way back to zero and then the corresponding video from the first value will play. In between it's showing the "image" I'm calling as a part of the video, but usually only one of them, not all of them. I'm new to the video library and processing &amp; arduino in general.
Thanks for your help!</p>

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

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


import processing.video.*;

Arduino arduino;

Movie oneDegree, twoDegrees, threeDegrees;


int sensorPin = 0;    // select the input pin for the potentiometer
int val;



void setup() {
  size(960, 540);
  arduino = new Arduino(this, Arduino.list()[3], 57600); //sets up arduino
   val = arduino.analogRead(sensorPin); 
   println(Arduino.list());
   oneDegree = new Movie(this, "comp1.mp4");
   twoDegrees = new Movie(this, "comp2.mp4");
   threeDegrees = new Movie(this, "comp3.mp4");


}

void draw() {
 val = arduino.analogRead(sensorPin); 
 println(val);
 image(oneDegree, 0, 0);
 image(twoDegrees, 0, 0);
 image(threeDegrees, 0, 0);

  if(val &gt; 10 &amp;&amp; val &lt; 348) { 
    oneDegree = new Movie(this, "comp1.mp4");
    oneDegree.play();
  }

  else if(val &gt; 348 &amp;&amp; val &lt; 686) {
  twoDegrees = new Movie(this, "comp2.mp4");
    twoDegrees.play();
  }

  else if(val &gt; 686 &amp;&amp; val &lt; 1024) {
   threeDegrees = new Movie(this, "comp3.mp4");
  threeDegrees.play();
  }

  if (oneDegree.time() == oneDegree.duration()) { //movie must be finished
twoDegrees.play();
  }
if (twoDegrees.time() == twoDegrees.duration()) { //movie must be finished
threeDegrees.play();
}
}

void movieEvent(Movie m) {
  m.read();
  /* if (m == oneDegree) {
    oneDegree.read();
  } 
  else if (m == twoDegrees) {
    twoDegrees.read();
  }
  else if (m == threeDegrees) {
    threeDegrees.read();
  }*/
}



/* void movieEvent(Movie ) {
  if (val &lt;= 348) {
    oneDegree.read();
  } 
  else if (val &gt; 348 &amp;&amp; val &lt;= 686) {
    twoDegrees.read();
  }

  else if (val &gt; 686 &amp;&amp; val &lt;= 1024) {
    threeDegrees.read();
  }
} */
</code></pre>
]]></description>
   </item>
   <item>
      <title>Arduino MQ-3 sensor sending signal input to p5.js</title>
      <link>https://forum.processing.org/two/discussion/22348/arduino-mq-3-sensor-sending-signal-input-to-p5-js</link>
      <pubDate>Tue, 02 May 2017 18:10:45 +0000</pubDate>
      <dc:creator>jstate1</dc:creator>
      <guid isPermaLink="false">22348@/two/discussions</guid>
      <description><![CDATA[<p>I am making a breathlyzer for a project using Arduino uno and p5.js. When I blow into the arduino sensor, it should display random circles on computer screen in p5.js. I am having problems with signal communication from my Arduino to p5.js. The connection is working, but the random circles are not displaying on my screen. Here is my code.</p>

<p>project.ino</p>

<pre><code>int level;
int LEDgreen2 = 2;
int LEDgreen3 = 3;
int LEDgreen4 = 4;
int LEDred7 = 7;
int LEDblue13 = 13;



void setup()
{ 
  Serial.begin(9600);
  pinMode(LEDgreen2, OUTPUT);
  pinMode(LEDgreen3, OUTPUT);
  pinMode(LEDgreen4, OUTPUT);
  pinMode(LEDred7, OUTPUT);
  pinMode(LEDblue13, OUTPUT);               
}

void loop()
{
    for(int time = 0;time &lt;= 3000;time++) //blow for 3 seconds
    {      
      digitalWrite(LEDblue13, HIGH);                          
      level = analogRead(A0);
      delay(1);
    }

digitalWrite(LEDblue13, LOW); 

if ( level &gt; 200) //no alch
{
  digitalWrite(LEDgreen2, HIGH); 
  digitalWrite(LEDgreen3, HIGH); 
  digitalWrite(LEDgreen4, HIGH);
}
else 
{
  digitalWrite(LEDred7, HIGH);
  Serial.println(level); 
}

delay(2000); //Wait 2 seconds to start over 
digitalWrite(LEDblue13,HIGH); //TURN ON BLUE LIGHT (START OVER)
digitalWrite(LEDgreen2, LOW); //turn off green LED
digitalWrite(LEDgreen3, LOW); //turn off green LED
digitalWrite(LEDgreen4, LOW); //turn off green LED
digitalWrite(LEDred7, LOW);//turn off red LED
}
</code></pre>

<p>p5.js</p>

<pre><code>var serial;
var inByte = 0;



function setup() {
  createCanvas(windowWidth, windowHeight);
  serial = new p5.SerialPort();
  serial.on('data', serialEvent)
  serial.open("COM3");
}

function draw() {

}


function serialEvent() {
 var inString = serial.readStringUntil('\r\n'); 
 inString = inString.trim();

 if (inString.length &gt; 0) {
   inByte = Number(inString);
   print(inByte);
 }
 if(inByte&gt;200){
   var x = random(width);
   var y = random(height);

   var r = random(255);
   var g = random(255);
   var b = random(255);

   fill(r, g, b, 100);
   ellipse(x, y, 50, 50);
 }
}
</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>Problem with communication between Arduino and Processing</title>
      <link>https://forum.processing.org/two/discussion/20319/problem-with-communication-between-arduino-and-processing</link>
      <pubDate>Tue, 17 Jan 2017 16:37:21 +0000</pubDate>
      <dc:creator>skizzo66</dc:creator>
      <guid isPermaLink="false">20319@/two/discussions</guid>
      <description><![CDATA[<p>I created this simple code with Arduino Ide where i send temperature in my serial monitor.</p>

<pre><code>int tmpin = A0;

void setup()
{
 pinMode(tmpin, INPUT);
 Serial.begin(9600);
}

void loop()
{
  //Serie di calcoli per arrivari prima alla tensione e poi alla temperatura
  int value = analogRead(A0);
  float voltage = (value / 1024.0) * 5.0;
  float temp = (voltage - 0.5) * 100;

  Serial.println(temp);
  delay(1000);
}
</code></pre>

<p>And later i wrote a code in processing to print the data in Processing:</p>

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

//Serial port
Serial port;

float val;

void setup()
{
  String portname = Serial.list()[0];
  port = new Serial(this, portname, 9600);
}

void loop()
{
  if(port.available() &gt; 0)
  {
    val = float(port.readString());
    println(val);
  }  
}
</code></pre>

<p>But nothing went writed in the box</p>
]]></description>
   </item>
   <item>
      <title>serial.write() five sensors of Arduino and Processing</title>
      <link>https://forum.processing.org/two/discussion/17213/serial-write-five-sensors-of-arduino-and-processing</link>
      <pubDate>Sun, 19 Jun 2016 14:25:15 +0000</pubDate>
      <dc:creator>goldi</dc:creator>
      <guid isPermaLink="false">17213@/two/discussions</guid>
      <description><![CDATA[<p>Hi I'm very new to all of this, hope to formulate the question right.</p>

<p>In my project I have 5 sensors connected to Arduino, which I want to interpret via Seria.write() --&gt; Processing.</p>

<p>Arduino:</p>

<pre><code>firstSens = 100 + (155 * digitalRead(8));
secondSens = analogRead(A1)/4;
thirdSens = analogRead(A2)/4;
fourthSens = humData;
fifthSens = tempData;

int sensData[6] = {firstSens, secondSens, thirdSens, fourthSens, fifthSens};

int i;
for (i = 0; i &lt; 5; i = i + 1) {
  Serial.write(sensData[i]);
}
</code></pre>

<p>Processing:</p>

<pre><code>serialInArray[serialCount] = inByte;
    serialCount++;

if (serialCount &gt; 4 ) {
  firstSens = serialInArray[0];
  secondSens = serialInArray[1];
  thirdSens = serialInArray[2];
  fourthSens = serialInArray[3];
  fifthSens = serialInArray[4];

  println(firstSens + "\t" + secondSens + "\t" + thirdSens + "\t" + fourthSens + "\t" + fifthSens);

  myPort.write('A');
  serialCount = 0;
</code></pre>

<p>My problem is that sensors find their place in Processing's array randomly, so for example arduino's <code>firstSens</code> could be Processing's <code>secondSens</code> or <code>fifthSens</code></p>

<p>Why is this happening and how can I control it?</p>
]]></description>
   </item>
   <item>
      <title>Very Slow Arduino Connection</title>
      <link>https://forum.processing.org/two/discussion/17268/very-slow-arduino-connection</link>
      <pubDate>Wed, 22 Jun 2016 15:55:28 +0000</pubDate>
      <dc:creator>CharlesDesign</dc:creator>
      <guid isPermaLink="false">17268@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>I'm trying to send a string of 16 sensor values from Arduino to Processing unfortunately, the connection is extremely slow. It  also reads fine from the Arduino serial monitor.</p>

<p>What I'm sending, the max for any of them is 255:</p>

<p><code>&lt;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0&gt;</code></p>

<p>Can anyone see what I'm doing wrong?</p>

<p>Thanks in advance!
Charles</p>

<p>ps: There actually seems to be a 15 second delay on the connection</p>

<p>To Processing:</p>

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

boolean newData = false;

void setup() {
  size(700, 400);
  frameRate(60);
  arduino = new Serial(this, Serial.list()[5], 9600);
}

void draw() {
  background(255);
  char startMarker = '&lt;';
  char endMarker = '&gt;';
  char read;

  String out = " ";

  while (arduino.available() &gt; 0 &amp;&amp; newData == false) {
    read = char(arduino.read());
    if (read != ',' &amp;&amp; read != '&lt;' &amp; read != '&gt;') {
      out = out + read;
    } else if (read == '&gt;') {
      newData = true;
    } else if (read == ',') {
      out = out + " " ;
    }
  }

  if (newData) {
    fill(0);
    textSize(30);
    text(out, width*0.1, width*0.2);
    newData = false;
  }
}
</code></pre>

<p>From Arduino:</p>

<pre><code>/Mux control pins
const int s0 = 12;
const int s1 = 11;
const int s2 = 9;
const int s3 = 8;

//Mux in "SIG" pin
const int SIG_pin = 2;

const int sample_rate = 40;
unsigned long last = 0;



void setup() {
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

  Serial.begin(9600);
}


void loop() {

  unsigned long current = millis();

  if ( current - last &gt; sample_rate) {
    Serial.print('&lt;');
    for (int i = 0; i &lt; 16; i++) {
      Serial.print(readMux(i) / 4);
      if (i &lt; 15) Serial.print(',');
    }
    Serial.println('&gt;');
  }

}


int readMux(int channel) {
  int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[16][4] = {
    {0, 0, 0, 0}, //channel 0
    {1, 0, 0, 0}, //channel 1
    {0, 1, 0, 0}, //channel 2
    {1, 1, 0, 0}, //channel 3
    {0, 0, 1, 0}, //channel 4
    {1, 0, 1, 0}, //channel 5
    {0, 1, 1, 0}, //channel 6
    {1, 1, 1, 0}, //channel 7
    {0, 0, 0, 1}, //channel 8
    {1, 0, 0, 1}, //channel 9
    {0, 1, 0, 1}, //channel 10
    {1, 1, 0, 1}, //channel 11
    {0, 0, 1, 1}, //channel 12
    {1, 0, 1, 1}, //channel 13
    {0, 1, 1, 1}, //channel 14
    {1, 1, 1, 1} //channel 15
  };

  //loop through the 4 sig
  for (int i = 0; i &lt; 4; i ++) {
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Arduino + LDR Sensor + Processing</title>
      <link>https://forum.processing.org/two/discussion/16615/arduino-ldr-sensor-processing</link>
      <pubDate>Sun, 15 May 2016 15:41:01 +0000</pubDate>
      <dc:creator>Vasco</dc:creator>
      <guid isPermaLink="false">16615@/two/discussions</guid>
      <description><![CDATA[<p>At the time i dont have the arduino or the light sensors, i will only work on that tomorrow =/. But at processing i'm trying some stuff. The idea is to have a video always in loop, but every time i take the light of a sensor (either if i put my finger on the sensor or a cloth) it show's another video, but when that sensor got light again it goes to the loop video.</p>

<p>This is what i got so far, still missing the keyPressed as a substitute of the sensors. The problem is the videos are all runing ate the same the time, and i've no idea how to do the keyPressing to call the other videos. Its the first time i'm using this library, and i really need help on this.</p>

<pre>
import processing.video.*;

String[] movieList = {"movie/x.mov", "movie/y.mov", "movie/w.mov", "movie/z.mov"};
Movie[] filmes = new Movie[movieList.length];

void setup() {
  size(1280, 720);
  //fullScreen();
  background (0);
  frameRate(60);

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

void draw() 
{
  for (int i = 0; i &lt; movieList.length; i++)
  {
    image(filmes[i], 0, 0);
  }
}

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

</pre>
]]></description>
   </item>
   <item>
      <title>Buffer file from Arduino Serial bytes (total newbie).</title>
      <link>https://forum.processing.org/two/discussion/16692/buffer-file-from-arduino-serial-bytes-total-newbie</link>
      <pubDate>Thu, 19 May 2016 03:07:03 +0000</pubDate>
      <dc:creator>valmishra</dc:creator>
      <guid isPermaLink="false">16692@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I am trying to create a circular buffer (in Processing) from the Arduino serial data. The circular buffer (an int 1D array) is periodically saved to a text file (by Processing) which can be read with an other program (Matlab).</p>

<p><strong>full workflow:</strong></p>

<p>analog input --&gt; Arduino's 10bits ADC --&gt;Serial.write(1200) --&gt; Processing creates a circular buffer with byte (array of bytes) --&gt; Processing save the array into text file --&gt; text file analysed by Matlab.</p>

<p>The system works poorly: 
The buffers files are saved way too slowly! It feels like there is a bottleneck somewhere.</p>

<p>When ever I change the input signal, it take a lot of time before my buffer text files are updated.</p>

<p>It is my first day coding in JAVA and I have been using Arduino for less than a week so I am a total noobie here! I would very much appreciate if some one could help me out. I am only used to Matlab and I have never done anything like this before so forgive my horrible coding!</p>

<p>Any advice would be welcome! I have also attached my codes bellow.</p>

<p>Thanks and have a great day!</p>

<p>Here are the codes:</p>

<p><strong>Arduino code workflow</strong></p>

<p>1)arduino receives an analog signal in pin A0 (a photoresistor for the moment).</p>

<p>2)arduino sends every bytes one by one to Processing.</p>

<pre><code>int thebyte=0;
int pin=A0;

void setup() {
  Serial.begin(1200);
  pinMode(pin,INPUT);
}

void loop() {
thebyte=analogRead(pin)/4;
Serial.write(thebyte);
delay(1);
}
</code></pre>

<p><strong>Processing code workflow</strong></p>

<p>1)setup an array for buffer, open serial port to Arduino
2)save the last received byte to the buffer last position (circular buffer: when buffersize is reach, the new bytes are written at the beginning of the array).</p>

<p>3)when Processing receives 1200 bytes (0.5 buffer size) or 2400 (full buffer size), the array is saved.</p>

<p>Variable "tic" (goes from 1 to 5) is here to save the arrays in different files so my matlab can load the last one without interfering with the writing.</p>

<pre><code>int bufferSize=2400;
int[] buffer;
int counter=0;
int tic=1;

void setup() {
  printArray(Serial.list());
  myPort= new Serial(this, Serial.list()[0], 1200);
  buffer = new int[bufferSize];
  println("start");
}


void draw() {
  if (counter==bufferSize) {counter=0;}

//add bytes to the array. 
  if (myPort.available()&gt;0) {
    mybyte= myPort.read();
    buffer[counter]=mybyte;

  } 
  else {println("port error");}

//print the full array in "1,2,3,4,5.txt".
  if (counter==bufferSize-1 || counter==bufferSize/2){ //println(counter);
      tic++;  
  if (tic==6){tic = 1;} //Six different files, so matlab can load them without interfering.
String filename = new String (String.valueOf(tic) + ".txt");
PrintWriter output;
output = createWriter(filename); 

for (int i = 0; i &lt; bufferSize; i++) {
output.println (buffer[i]);
}

output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file


}
  counter++;
  delay(1);
}
</code></pre>

<p><strong>Matlab workflow</strong></p>

<p>1)matlab loads the last modified text file</p>

<p>(among 1.txt, 2.txt, 3.txt, 4.txt, 5.txt);</p>

<p>2)matlab can do some computations on it</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>opacity low and high on image through tint()</title>
      <link>https://forum.processing.org/two/discussion/16497/opacity-low-and-high-on-image-through-tint</link>
      <pubDate>Sun, 08 May 2016 19:32:44 +0000</pubDate>
      <dc:creator>KatheElisabeth</dc:creator>
      <guid isPermaLink="false">16497@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I am almost finished with my code but i am experience a little problem. I am writing a program where i have one background image and one image "on top of the background" which changes its opacity with a potentiometer. When the potentiometer is at 0 the opacity on the image on top of the background is 0%, and when the potentiometer is 1023 the image on top of the background is 100%. 
So far i've managed to make processing listen to the potentiometer, and it is able to fade in through the changing of opacity, so when the potentiometer is turned up from 0 to 1023, the image's opacity goes from 0-100. BUT it will not fade out again. eg. when the potentiometer is at 1023 and i go down to 500, the image's opacity does not follow and the image does not fade again. 
I have a deadline on this project tomorrow, so i appriciate all the help i can get. 
Here is my code from processing:</p>

<pre><code>import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int sensorPin = 2; 

PImage bg;
PImage img;
PImage imgstreg;
float mappedValue;

void setup(){
arduino = new Arduino(this, Arduino.list()[2], 57600);
  arduino.pinMode(2, Arduino.OUTPUT);


  size(550,770);
    img = loadImage("udensvedbilledemini.jpg");
    background(img);

}
void draw(){
    imgstreg = loadImage("svedbilledemini.jpg");
float sensorValue = arduino.analogRead(2);
println(sensorValue);

//i mapped the sensor value from 0-1500 instead of 1023, as the opacity gained too much in too little time
mappedValue = map(sensorValue, 0, 1500, 0, 100);

tint(255, mappedValue);
image(imgstreg,0,0);
delay (400);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why it does not work? Piezo sensor, firmata, processing and Arduino</title>
      <link>https://forum.processing.org/two/discussion/16219/why-it-does-not-work-piezo-sensor-firmata-processing-and-arduino</link>
      <pubDate>Sun, 24 Apr 2016 02:06:26 +0000</pubDate>
      <dc:creator>zheng</dc:creator>
      <guid isPermaLink="false">16219@/two/discussions</guid>
      <description><![CDATA[<p>import processing.serial.*;
import org.firmata.*;
import cc.arduino.*;</p>

<p>Arduino arduino;</p>

<p>int S1 = 0;
int A;
void setup() {
  size(500, 500);
  ellipseMode(CENTER);</p>

<p>arduino = new Arduino(this, Arduino.list()[0], 57600);</p>

<p>arduino.pinMode(S1, Arduino.INPUT);
}</p>

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

<p>A = arduino.analogRead(S1);
  println(A);
  if (A ==1) {
   ellipse(width/2,height/2,100,100);
  }
}</p>
]]></description>
   </item>
   <item>
      <title>Ramon64917021 (Arduino syntax errors)</title>
      <link>https://forum.processing.org/two/discussion/15162/ramon64917021-arduino-syntax-errors</link>
      <pubDate>Sat, 27 Feb 2016 21:03:23 +0000</pubDate>
      <dc:creator>Ramon64917021</dc:creator>
      <guid isPermaLink="false">15162@/two/discussions</guid>
      <description><![CDATA[<p>Estoy intentando cargar un programa y en el momento de verificarlo me salen un montón de errores
de los que no entiendo nada. Además no se nada de inglés.</p>

<p>¿Alguien me puede ayudar?</p>

<p>Gracias y perdón por las molestias</p>

<pre><code> const int inPin = A0;  // pin de entrada
 const int ledPin = 13; // pin del led
 int val = 0;

 void setup(); {
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
 }

 void loop() {
    val = analogRead(inPin); // se lee el valor del pin de entrada
    digitalWrite(ledPin, HIGH); // enciende el led
    delay(val); // espera el valor leído en la entrada en milisegundos
    digitalWrite(ledPin, LOW); // apaga el led
    delay(val); // espera el valor leído en la entrada en milisegundos 
    int sensorValue = analogRead(inPin); // leemos el valor
    delay(1);   // pausa para estabilidad entre ciclos     
 }

 map() {
    int x = 11;
    int y = constrain(x,0,10,); // y tendra valor 10
    int z = constrain(x,0,100); // z tendrá valor 11 por estar entre los limites   
 }
}
</code></pre>

<p>Arduino:1.6.6 Hourly Build 2015/07/15 12:54 (Windows 8.1), Placa:"Arduino Uno"</p>

<p>sketch_feb27b:21: error: macro "constrain" passed 4 arguments, but takes just 3<br />
sketch_feb27b:4: error: expected unqualified-id before '{' token<br />
sketch_feb27b:19: error: ISO C++ forbids declaration of 'map' with no type [-fpermissive]<br />
sketch_feb27b.ino: In function 'int map()':<br />
sketch_feb27b:21: error: 'constrain' was not declared in this scope<br />
sketch_feb27b.ino: At global scope:<br />
sketch_feb27b:24: error: expected declaration before '}' token<br />
macro "constrain" passed 4 arguments, but takes just 3</p>

<p>This report would have more information with
  "Show verbose output during compilation"
  activala desde Archivo &gt; Preferencias</p>
]]></description>
   </item>
   <item>
      <title>Ketai Bluetooth dataevent interrupt</title>
      <link>https://forum.processing.org/two/discussion/14012/ketai-bluetooth-dataevent-interrupt</link>
      <pubDate>Wed, 16 Dec 2015 10:35:17 +0000</pubDate>
      <dc:creator>demket</dc:creator>
      <guid isPermaLink="false">14012@/two/discussions</guid>
      <description><![CDATA[<p>Hi, in my project, arduino sends two byte data by osc protocol. In android side, mobile phone get them via bluetooth (ketai-osc) and send to other PC by osc meessage as gateway. Arduino sends very fast but android side lost data and set zero "0" value of float value1 and value2.</p>

<p>Where is my fault? why variables (value1,value2) get 0?</p>

<p>Android Code:
`import android.content.Intent;
import android.os.Bundle;</p>

<p>import ketai.net.bluetooth.*;
import ketai.ui.*;
import ketai.net.*;
import oscP5.*;
import netP5.*;</p>

<p>OscP5 oscP5;
NetAddressList myNetAddressList = new NetAddressList();
int myListeningPort = 32000;
int myBroadcastPort = 12000;
String myConnectPattern = "/server/connect";
String myDisconnectPattern = "/server/disconnect";</p>

<p>KetaiBluetooth bt;
String info = "";
KetaiList klist;
boolean isConfiguring = true;
String UIText;
float value1, value2;
ArrayList names;
String aktar = "Gelen: ";</p>

<p>int xPos = 1;<br />
float height_old = 0;
float height_new = 0;
int say = 0;</p>

<p>void onCreate(Bundle savedInstanceState) {</p>

<p>super.onCreate(savedInstanceState);
  bt = new KetaiBluetooth(this);
}</p>

<p>void onActivityResult(int requestCode, int resultCode, Intent data) {
  bt.onActivityResult(requestCode, resultCode, data);
}</p>

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

<p>background(0);</p>

<p>oscP5 = new OscP5(this, myListeningPort);</p>

<p>bt.start();</p>

<p>stroke(255);
  fill(0xff); 
  textSize(32);</p>

<p>if (bt.getDiscoveredDeviceNames().size() &gt; 0)
  klist = new KetaiList(this, bt.getDiscoveredDeviceNames());
  else if (bt.getPairedDeviceNames().size() &gt; 0)
  klist = new KetaiList(this, bt.getPairedDeviceNames());</p>

<p>bt.discoverDevices();</p>

<p>xPos = (width/4)+1;<br />
  height_old = (height/2)-5;
  stroke(0,0xff,0xff);
  strokeWeight(5);
  line(((width/4)-3),0,((width/4)-3),height);
  line(0,(height/2),width,(height/2));</p>

<p>stroke(0xff, 0, 0);
  strokeWeight(2);</p>

<p>}</p>

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

<p>background(0);</p>

<p>value1 = map(value1, 0, 1023, 0, (height/2)-5);
  height_new = (height/2)-5 - value1; 
  stroke(0);
  line(xPos,0,xPos,(height/2)-5);
  stroke(0xff, 0, 0);
  line(xPos - 1, height_old, xPos, height_new);
  height_old = height_new;</p>

<p>if (xPos &gt;= width) {
   xPos = width/4;
  }
  else {
   xPos=xPos + 2;
  }
}</p>

<p>void onBluetoothDataEvent(String who, byte[] data)
{
  KetaiOSCMessage m = new KetaiOSCMessage(data);
  OscMessage myOscMessage = new OscMessage("");</p>

<p>if (m.isValid())
  {</p>

<pre><code>if (m.checkAddrPattern("/sti"))
{
  if (m.checkTypetag("ii"))
  {
    value1= m.get(0).intValue();
    value2 = m.get(1).intValue();
    println("Gelen: "+value1+","+value2);
    myOscMessage.add(value1);
    myOscMessage.add(value2);
    oscP5.send(myOscMessage, myNetAddressList);
  }
}
</code></pre>

<p>}
}</p>

<p>void onKetaiListSelection(KetaiList klist)
{
 String selection = klist.getSelection();
 bt.connectToDeviceByName(selection);</p>

<p>klist = null;
}</p>

<p>void oscEvent(OscMessage theOscMessage) {</p>

<p>if (theOscMessage.addrPattern().equals(myConnectPattern)) {
    connect(theOscMessage.netAddress().address());
  }
  else if (theOscMessage.addrPattern().equals(myDisconnectPattern)) {
    disconnect(theOscMessage.netAddress().address());
  }
  else {
    oscP5.send(theOscMessage, myNetAddressList);
  }
}</p>

<p>private void connect(String theIPaddress) {
     if (!myNetAddressList.contains(theIPaddress, myBroadcastPort)) {
       myNetAddressList.add(new NetAddress(theIPaddress, myBroadcastPort));
     }
 }</p>

<p>private void disconnect(String theIPaddress) {
if (myNetAddressList.contains(theIPaddress, myBroadcastPort)) {
    myNetAddressList.remove(theIPaddress, myBroadcastPort);
}
 }`</p>

<p>Arduino code:
`uint8_t buf[20];
char gelenveri = 0;
int val1=512 , val2;</p>

<p>void setup() {
  Serial.begin(9600);
  Serial1.begin(115200);
  pinMode(13,OUTPUT);
  buf[0] = 47;   // /
  buf[1] = 115;  // s
  buf[2] = 116;  // t
  buf[3] = 105;  // i
  buf[4] = 0;
  buf[5] = 0;
  buf[6] = 0;
  buf[7] = 0;
  buf[8] = 44;   // ,
  buf[9] = 105;  // i
  buf[10] = 105; 
  buf[11] = 0;
  buf[12] = 0; // ilk veri byte3<br />
  buf[13] = 0; // ilk veri byte2<br />
  buf[14] = 0; // ilk veri byte1<br />
  buf[15] = 0; // ilk veri byte0
  buf[16] = 0; // ikinci veri byte3
  buf[17] = 0; // ikinci veri byte2
  buf[18] = 0; // ikinci veri byte1
  buf[19] = 0; // ikinci veri byte0</p>

<p>}</p>

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

<pre><code>  val1 = analogRead(A0);
  val2 = analogRead(A1);



  buf[14] = val1&gt;&gt;8;
  buf[15] = val1%256;
  buf[18] = val2&gt;&gt;8;
  buf[19] = val2%256; 

  Serial1.write(buf, sizeof(buf));


  delay(50);
</code></pre>

<p>}`</p>
]]></description>
   </item>
   <item>
      <title>How to make an image fade to another image when a certain amount of light falls on a LDR?</title>
      <link>https://forum.processing.org/two/discussion/13270/how-to-make-an-image-fade-to-another-image-when-a-certain-amount-of-light-falls-on-a-ldr</link>
      <pubDate>Mon, 26 Oct 2015 10:25:54 +0000</pubDate>
      <dc:creator>blabla</dc:creator>
      <guid isPermaLink="false">13270@/two/discussions</guid>
      <description><![CDATA[<p>Hi, 
I have been trying to make an image transistion to another image when a certain amount of light falls on a LDR, and transistions back when that light is not shining on the LDR anymore. However, the piece of code is not working properly.
I am new to processing, so there is a good chance that I am doing it completely wrong. It would be lovely if someone could help me achieve the fade in and out! Thanks in advance!
Here is a part of my code, and what I have tried to do for the fade:</p>

<pre><code>int transparency = 0;

void setup() {
  img = loadImage(imgFileName+"."+fileType);
  bla = loadImage("mermaid.jpg");
  size(img.width, img.height);
  image(img, 0, 0);

  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  arduino.pinMode(ledPin, Arduino.OUTPUT);
  arduino.pinMode(sensorPin, Arduino.INPUT);
}
void draw() {
      int analogValue =  arduino.analogRead(sensorPin);
      println(analogValue);

      if (analogValue &gt; 900) {
        noTint();
        image(bla, 0, 0);
      } else {
        while (column &lt; width-1) {
          img.loadPixels(); 
          sortColumn();
          column++;
          img.updatePixels();
        }

        while (row &lt; height-1) {
          img.loadPixels(); 
          sortRow();
          row++;
          img.updatePixels();
        }

     if (transparency &lt; 255) {
          transparency++; 
        }
        tint(255, 255, 255, transparency);
        image(img, 0, 0);
        //automatically save the image 
        if (!saved &amp;&amp; frameCount &gt;= loops) {
          saveFrame(imgFileName+"_"+mode+".png");
          saved = true;
        }
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Send Data from Arduino to Processing over serial // help please</title>
      <link>https://forum.processing.org/two/discussion/11649/send-data-from-arduino-to-processing-over-serial-help-please</link>
      <pubDate>Sat, 11 Jul 2015 04:37:06 +0000</pubDate>
      <dc:creator>Casey_Scalf</dc:creator>
      <guid isPermaLink="false">11649@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to send data from an Arduino Uno to Processing.</p>

<p>Video of situation: <span class="VideoWrap"><span class="Video YouTube" id="youtube-s68aYfD71WY"><span class="VideoPreview"><a href="http://youtube.com/watch?v=s68aYfD71WY"><img src="http://img.youtube.com/vi/s68aYfD71WY/0.jpg" width="640" height="385" border="0" /></a></span><span class="VideoPlayer"></span></span></span></p>

<p>I made a simple sketch which does this no problem. It is only when I try to have the Arduino send data to Procesing in an "if conditional" from an analog sensor reading that I run into trouble.</p>

<p>For instance, the simple send from Arduino looks like this:</p>

<pre><code>int ledPin = 13;

void setup()
{
  Serial.begin(9600);
   pinMode(ledPin, OUTPUT);
}
void loop()
{
  Serial.write(1);
   digitalWrite(ledPin, HIGH);
  delay(200);
  Serial.write(0);
   digitalWrite(ledPin, LOW);
  delay(200);
}
</code></pre>

<p>And the corresponding Processing code looks like this:</p>

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

Serial myPort;  // Create object from Serial class
int val;

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

  rectMode(CENTER);
}

void draw()
{
  background(0);
  fill(255);

  if (myPort.available()&gt;0)
  {
    val = myPort.read();
  }
  println(val);

  if (val == 1)  {
    rect(width/2, height/2, 30, 30);
  }
}
</code></pre>

<p>It makes a white square appears when the number "1" is sent to Processing. It works so simple. It works every time. I was so pleased.</p>

<p>However, when I try it with the next Arduino sketch, nothing ever happens. It always stays on "0" even though I can see on the Arduino the LED turns on showing that yes, this piece of code has run. The Processing portion can stay exactly the same.</p>

<p>Why am I not seeing it work right? I have tried so many things. This tells me it's either painfully obvious or I've done something horribly karmically wrong and this is my punishment.</p>

<p>Thank you for nay tips.</p>

<pre><code>    // Used to interface with electronic drum pads
    // Using a piezo sensor
    // Casey Scalf 2015


    int ledPin = 13;
    int padPin = 0; // Red
    // Black is Ground

    byte val;
    byte a = 0;

    int THRESHOLD = 20;

    void setup() {

      Serial.begin(9600);

      pinMode(ledPin, OUTPUT);
    }

    void loop() {

      val = analogRead(padPin);

      if (val &lt;= THRESHOLD) {
        digitalWrite(ledPin, LOW);
        a = 0;
        Serial.write(a);
      }

        if (val &gt;= THRESHOLD) {
        digitalWrite(ledPin, HIGH);
        a = 1;
        Serial.write(a);
      }

    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Arduino sensor update in processing</title>
      <link>https://forum.processing.org/two/discussion/12685/arduino-sensor-update-in-processing</link>
      <pubDate>Fri, 25 Sep 2015 15:03:00 +0000</pubDate>
      <dc:creator>sobren15</dc:creator>
      <guid isPermaLink="false">12685@/two/discussions</guid>
      <description><![CDATA[<p>**Hey all, I am using Arduino and Processing. On my Arduino I am simply using the Standard Firmata. My goal is for the sensor data of Arduino to be written out in Processing in a readable way. my first code was: 
This sort of "cheats" with the white rectangle over the text every-time to update to the new information. **</p>

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

<p>Arduino arduino;
int sensorpin = 0;                 // analog pin used to connect the sharp sensor
int val = 0;                 // variable to store the values from sensor(initially zero)</p>

<p>void setup()
{
  //println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  background(255);
  size(1000, 1000);
}</p>

<p>void draw()
{
  val=arduino.analogRead(sensorpin);   // reads the value of the sharp sensor
  stroke (255);
  fill(255);
  rect(0, 0, 400, 400);</p>

<p>if (val &gt;= 0)
  { 
    textSize(32);
    fill(0, 102, 153, 204);
    text("sensor pin value is ", 10, 30);<br />
    text(val, 10, 60);
    println (val);
  } 
  delay(300);</p>

<p>}</p>

<p>**** My second goals is for when there is a mouseclicked, I want the data to change color but to still update. This is where I am having trouble.  The Sensor data changes to the current value in the new color when clicked but not in between  (when not clicked) ... any ideas?****
import processing.serial.*;
import cc.arduino.*;</p>

<p>Arduino arduino;
int sensorpin = 0;                 // analog pin used to connect the sharp sensor
int val = 0;                 // variable to store the values from sensor(initially zero)
int DayNight = 0; 
void setup()
{
  //println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  background(255);
  size(1800, 800);
}</p>

<p>void draw()
{<br />
  val=arduino.analogRead(sensorpin);   // reads the value of the sharp sensor</p>

<p>}</p>

<p>void mouseClicked() {
  if (DayNight == 0) {
    val=arduino.analogRead(sensorpin);<br />
    stroke (255);
    fill(255);
    rect(0, 0, 400, 400);</p>

<pre><code>fill(0, 102, 153, 204);
textSize(32);
text("sensor pin value is ", 10, 30);  
text(val, 10, 60);
println (val);

DayNight = 1;
</code></pre>

<p>} else {
    val=arduino.analogRead(sensorpin);<br />
     stroke (255);
  fill(255);
  rect(0, 0, 400, 400);</p>

<pre><code>fill(0, 102, 13, 104); 
textSize(32);
text("sensor pin value is ", 10, 30);  
text(val, 10, 60);
println (val);
DayNight = 0;
</code></pre>

<p>}
}</p>
]]></description>
   </item>
   <item>
      <title>photosensor triggers sound, how do I stop the sound from looping?</title>
      <link>https://forum.processing.org/two/discussion/11967/photosensor-triggers-sound-how-do-i-stop-the-sound-from-looping</link>
      <pubDate>Tue, 04 Aug 2015 20:10:56 +0000</pubDate>
      <dc:creator>charlie78</dc:creator>
      <guid isPermaLink="false">11967@/two/discussions</guid>
      <description><![CDATA[<p>Hello! I'm writing a code for a Lilypad and one of the inputs I'm hoping to use is a photosensor, which should trigger a sound when the sensor is covered. That bit is all working fine, but the sound is looped and I can't figure out how to stop that? I tried <code>noLoop()</code> but that just plays the sound when the Lilypad is first connected, and nothing happens when the sensor is covered.. This is my code:</p>

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

Minim minim;
Event event_example;
Arduino arduino;

int input_example, led; //the led just gives additional feedback if the the sensor was covered 

void setup() {
  size(470, 280);

  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);

  input_example = 2; //this is the pin the photo resistor is connected to
  led = 6; //this is the pin that the led is connected to

  arduino.pinMode(input_example, Arduino.INPUT);

  minim = new Minim(this);
  event_example= new Event("audio/example.wav");
}

void draw() {

  if (arduino.analogRead(input_example) &lt; 500) {
    event_example.trigger();
    arduino.digitalWrite(led, Arduino.HIGH);
  } else {
    event_example.stop();
    arduino.digitalWrite(led, Arduino.LOW);
  }
}

//The following code is in another tab

public class Event {

  boolean flag;
  AudioSample sample;

  public Event (String file) {
    sample = minim.loadSample(file, 512);
    flag = false;
  }

  void trigger() {
    sample.trigger();
    flag = true;
  }

  void stop() {
    flag = false;
  }
}
</code></pre>

<p>Any help is much appreciated!!</p>
]]></description>
   </item>
   <item>
      <title>ADC help</title>
      <link>https://forum.processing.org/two/discussion/2981/adc-help</link>
      <pubDate>Tue, 11 Feb 2014 09:59:00 +0000</pubDate>
      <dc:creator>Javier</dc:creator>
      <guid isPermaLink="false">2981@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone. It's my first post in this forum so excuse me if I have some errors.</p>

<p>I want to make an arduino analogRead from Processing. I can read the data but I need the reading to be faster. I know how to configure the ADC speed with arduino but not in Processing (I am programming everything in Processing).</p>

<p>And I have another problem. I want to set de ADC voltage reference to 1.1V. Again, I know how to do it with Arduino (analogReference) but not with Processing.</p>

<p>Can anyone lend me a hand with this?</p>

<p>Thank you very much!</p>
]]></description>
   </item>
   <item>
      <title>Analog pins with Processing and Arduino</title>
      <link>https://forum.processing.org/two/discussion/201/analog-pins-with-processing-and-arduino</link>
      <pubDate>Tue, 08 Oct 2013 19:42:36 +0000</pubDate>
      <dc:creator>iamdahm</dc:creator>
      <guid isPermaLink="false">201@/two/discussions</guid>
      <description><![CDATA[<p>Hey all.</p>

<p>I'm building an arcade machine with an Arduino Duemilanove ATmega328p and Processing. I want to use x4 rotary encoders and a joystick to control some features of my game. I have used all of my digital pins for 3 rotary encoders with built-in buttons (3 pins each), and the remainder for the joystick (4 pins). I have one more rotary encoder hooked up to the analog pins 3-5, but I am having trouble with interpreting numbers I return from the analogRead() method. I tried digitalRead() instead, but I am always left with a reading of 0 on both pins.  Does anybody have experience with rotary encoders and analog inputs?</p>
]]></description>
   </item>
   </channel>
</rss>