Go Down

Topic: problem with delay - processing (Read 860 times) previous topic - next topic

mitcho

Mar 12, 2006, 06:39 pm Last Edit: Mar 12, 2006, 06:42 pm by mitcho Reason: 1
I send messages from the board to processing - i send a 1, 2 or 3. i know this works because i trace in the wiring console.

i setup the processing code below to change color of square every second based on number sent from board. it works but something wrong with delay. instead of taking 1 second, it takes much longer... is there something wrong with my code thats causing this?



import processing.serial.*;
Serial port;
int val;
      
void setup()
{
  size(200, 200);
  noStroke();
  framerate(10);
 
  println(Serial.list());

  port = new Serial(this, Serial.list()[1], 9600);
}
 
void draw()
{
  if( 0 < port.available() )
  {
    val = port.read();
  }
  background(#222222);  
  if( val == 1 )
  {
    fill(#00FF43);
    print("\n");
    print(val);
  }else if( val == 2 ){
    fill(#FFBF00);
    print("\n");
    print(val);
  }
 else if( val == 3 ){
    fill(#FF0000);
    print("\n");
    print(val);            
  }
  rect(50, 50, 100, 100);
   delay(1000);
}

Go Up