We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Drawing analog inputs (Read 1434 times)
Drawing analog inputs
Feb 5th, 2010, 5:13am
 
Hi there,
I'm new to this Processing forum and I appologise if this is not the right place for posting my question.
Basically, I manage to connect through firmata to my arduino which has a photoresistor connected on one of theanalog inputs. What I'm trying to achieve in processing is a drawing of this analog input following a timeline : I would pull the analog input every second or so and output it on a timeline. I could do all this by myself but I guess I'm not the first one to try it. I've been reviewing all contribute librairies but couldn't find any suitable. Maybe I'm looking for the wrong thing ?
Anyway, if anyone has a clue of how to output dynamically an anlog value following a timeline without re-inventing the wheel, would be nice to know ...
Smiley

Thanks,
Gilles
Re: Drawing analog inputs
Reply #1 - Feb 14th, 2010, 1:31pm
 
Hey, you can draw a simple graph from an analog input fairly easily if that's what you're after. This is from the arduino examples btw - if you wanted anything more specific let me know!

Arduino code

Code:


int analogPin = 0;
float xPos = 0;
void setup(){
serial.begin(9600);
}
void draw(){
serial.println(analogRead(analogPin));
delay(20); //change the delay time here
}


Processing code

Code:

import processing.serial.*;
Serial port

void setup(){
 size(600,255);
 port = new Serial(this, Serial.list[0], 9600);
 port.bufferUntil('\n');
}

void draw(){
}

void serialEvent (Serial port) {

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

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

   float inByte = float(inString);
   inByte = map(inByte, 0, 1023, 0, height);

   stroke(inByte,0,255);
   noFill();
   line(xPos, height - inByte, xPos, height);

   if (xPos >= width) {
     xPos = 0;
     background(0);
   }
   else {
     xPos++;
   }
 }
}
Page Index Toggle Pages: 1