Hello,
Thanks for your answer..
Bellow is the simplest code I could build to explain what I want..I know it is big,sorry, but is the only way I found!
I want to get the values from the serial port and use them in diferent classes, one to show the values and another two to plot the values.
- //Main Class
- import napplet.*;
- import processing.serial.*;
- Serial myPort;
- float sensor1=0;
- float sensor2=0;
- void setup() {
- size(800, 400);
- // List all the available serial ports
- 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()[0], 9600);
- // don't generate a serialEvent() unless you get a newline character:
- myPort.bufferUntil('\n');
-
- NAppletManager nappletManager = new NAppletManager(this);
- nappletManager.createNApplet("Animator", 400, 0);
- nappletManager.createNApplet("BouncyBubbles", 400, 205);
- nappletManager.createNApplet("Convolution", 100, 0);
-
- }
- void draw() {
- background(255);
- }
- void serialEvent (Serial myPort)
- {
- // get the ASCII string:
- String input = myPort.readStringUntil('\n');
-
- if (input != null) {
- // trim off any whitespace:
- input= trim(input);
- // convert to an int and map to the screen height:
- float inByte = float(split(input, ",")); //split the input coming in the serial port by comas
-
- if (infos.length >=8) //3 e o numero de variaveis que importo do arduino "ainda nao percebi bem porque e' necessario este if"
- {
- sensor1 = infos [0];
- sensor2 = infos [1];
- }
-
- sensor1 = map(sensor1, 0, 1023, 0, 195);
- sensor2 = map(sensor2, 0, 1023, 0, 195);
-
- }
- }
- //Sensor 1 Plot Class
- public class Animator extends NApplet {
-
- int lineX_T=0;
- void setup ()
- {
- size (400,195);
- }
- void draw ()
- {
- stroke(0,20,100);
- strokeWeight(2);
- line (lineX_T,height,lineX_T,height-inByte);
- lineX_T ++;
-
- if (lineX_T > width)
- {
- lineX_T=0;
- background (200);
- }
- }
- }
-
- //Sensor 2 Plot Class
- public class BouncyBubbles extends NApplet {
- int lineX_H=0;
- void setup ()
- {
- size (400,195);
- }
- void draw ()
- {
- stroke(0,20,100);
- strokeWeight(2);
- line (lineX_H,height,lineX_H,height-inByte);
- lineX_H ++;
-
- if (lineX_H > width)
- {
- lineX_H=0;
- background (200);
- }
- }
- }
- //Show sensor 1 value Class
- public class Convolution extends NApplet {
- PFont f; // STEP 2 Declare PFont variable
-
- void setup() {
- size(200,200);
- f = loadFont("ArialMT-18.vlw"); // STEP 3 Load Font
- }
- void draw() {
- background(255);
- textFont(f,30); // STEP 4 Specify font to be used
- fill(0); // STEP 5 Specify font color
- text(sensor1,10,100); // STEP 6 Display Text
- }
- }
This is my code but it is not rigth, because I don't know how to get the values from the main class to the others and use the values them (the values)...
You can see an example how I want it to work here
http://www.openprocessing.org/sketch/62061.
Is the same example but instead of the values from the serial port I used the mouse position values..Take a look at this..I think is better for you understand!
Thank you very much for your help
Greetings