Pages: [1]   Go Down
Author Topic: error inside Serial.<init>()  (Read 635 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

//import Serial communication library
import processing.serial.*;

//init variables
Serial commPort;
float tempC;
float tempF;
int yDist;
PFont font12;
PFont font24;
float[] tempHistory = new float[100];

void setup()
{
  //setup fonts for use throughout the application
  //font12 = loadFont("Verdana-12.vlw");
  //font24 = loadFont("Verdana-24.vlw");
 
  //set the size of the window
  size(210, 200);
 
  //init serial communication port
  commPort = new Serial(this, "COM1", 9600);
 
  //fill tempHistory with default temps
  for(int index = 0; index<100; index++)
    tempHistory[index] = 0;
}

void draw()
{
  //get the temp from the serial port
  while (commPort.available() > 0)
  {
    tempC = commPort.read();
 
    //refresh the background to clear old data
    background(123);

    //draw the temp rectangle
    colorMode(RGB, 160);  //use color mode sized for fading
    stroke (0);
    rect (49,19,22,162);
    //fade red and blue within the rectangle
    for (int colorIndex = 0; colorIndex <= 160; colorIndex++)
    {
      stroke(160 - colorIndex, 0, colorIndex);
      line(50, colorIndex + 20, 70, colorIndex + 20);
    }
   
    //draw graph
    stroke(0);
    fill(255,255,255);
    rect(90,80,100,100);
    for (int index = 0; index<100; index++)
    { 
      if(index == 99)
        tempHistory[index] = tempC;
      else
        tempHistory[index] = tempHistory[index + 1];
      point(90 + index, 180 - tempHistory[index]);
    }
 
    //write reference values
    fill(0,0,0);
    textFont(font12);
    textAlign(RIGHT);
    text("212 F", 45, 25);
    text("32 F", 45, 187);
 
    //draw triangle pointer
    yDist = int(160 - (160 * (tempC * 0.01)));
    stroke(0);
    triangle(75, yDist + 20, 85, yDist + 15, 85, yDist + 25);
 
    //write the temp in C and F
    fill(0,0,0);
    textFont(font24);
    textAlign(LEFT);
    text(str(int(tempC)) + " C", 115, 37);
    tempF = ((tempC*9)/5) + 32;
    text(str(int(tempF)) + " F", 115, 65);
  }
}

am feeding  the output values of sensor using simulator for arduino software..now when ever am giving the same port number to both the applications am getting the error!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
now when ever am giving the same port number to both the applications am getting the error!
In the history of the universe, there has been more than one error. You are not getting "the error". You are getting an error, but you haven't told us that there error is.

Quote
am feeding  the output values of sensor using simulator for arduino software.
So, you are not using an Arduino at all? Why are you here, then?
Logged

Miami/Florida
Offline Offline
Sr. Member
****
Karma: 14
Posts: 344
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In the history of the universe, there has been more than one error. You are not getting "the error". You are getting an error, but you haven't told us that there error is.

You make me laugh most of the times... smiley-lol

Your code.

while (commPort.available() > 0)
  {
    tempC = commPort.read();
   // and a million things here inside the while loop?
 }


//maybe better

if (commPort.available() > 0)
  {
    tempC = commPort.read();
    commPort.clear(); //let's clear the Port after reading the value.
  }

or

while(commPort.available()<1)
{}
tempC = commPort.read();
commPort.clear();

This is probably not the source of your error; which by the way like Paul mentioned we don't know what it is. Maybe just another way to write the code.



Logged

Perseverance is 90% of the solution. The remaining 10% is more perseverance.

Pages: [1]   Go Up
Jump to: