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.
IndexProgramming Questions & HelpSyntax Questions › loadImage issue: doesn't display the 2nd image
Page Index Toggle Pages: 1
loadImage issue: doesn't display the 2nd image (Read 587 times)
loadImage issue: doesn't display the 2nd image
Apr 20th, 2007, 4:48am
 
Hi, we're completely lost with Processing (and Arduino). Basically we're using a heat sensor and depending on what range the temperature is in, it'll show a different image. Our problem is that it'll only show the first image based on the first reading, and even if the temperature changes to fit into the other range, the image will remain the same. We want the image to change each time it switches ranges.

We're new to this and we've searched the Reference and looked up similar codes and we're STILL lost. If someone could help us, that would be great! Here's our code:




import processing.serial.*;

String portName= "/dev/tty.usbserial-A3000YM6"; //declare the name of the port
Serial port;

PImage a;
PImage b;
      int reading = 0;

void setup()
{

size(100, 100);
PImage a;
a = loadImage("helmet_green.jpg");
 image(a, 0, 0);
 
PImage b;
b = loadImage("helmet2.jpg");
image(b, 0, 0);
 
 println("Available serial ports:");
 println(Serial.list());

 // Uses the first available port
 port = new Serial(this, portName, 9600);


}

void draw()
{
   int reading = 0;
   while (port.available() > 0)
   {
   reading = port.read();
   
   if(reading < 62)
   {

    b = loadImage("helmet2.jpg");
    image(b, 0, 0);
    println("Show image 1");
    delay(1000);
   }
   else if(reading >= 62)
   {
   
    a = loadImage("helmet_green.jpg");
    image(a, 0, 0);
    println("Show image 2");
    delay(1000);
     
   }
   println(reading);
   reading = 0;
 }


}



Thanks in advance for any help you can offer us!
Re: loadImage issue: doesn't display the 2nd image
Reply #1 - Apr 20th, 2007, 2:22pm
 
are you only sending one character per second from the arduino board?

in this program, you're reading a single character from the port, then delaying a full second. unless you're only sending one character per second, my guess would be that the port is filling up with bytes during the delay, so it's simply going to take a long time before the screen updates properly.
Re: loadImage issue: doesn't display the 2nd image
Reply #2 - Apr 22nd, 2007, 7:02am
 
hey,

thanks for the response. i think we've decided to ditch that idea all together as the sensor we were using barely works and
that code was just so much trouble.

but thank you so much anyway for the help.
Page Index Toggle Pages: 1