Wednesday, September 8, 2010

Processing-Arduino 1: Mouse to LED

import processing.serial.*;

Serial port; //create object from "serial" class

void setup() {
size(200, 200);
noStroke();
frameRate(10);
//open the port that the board is connected to and use the same speed (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
background(255);
if (mouseOverRect() == true) {
fill(204);
port.write("H");
} else {
fill(0);
port.write("L");
}
rect(50, 50, 100, 100);
}

boolean mouseOverRect() {
return((mouseX >= 50) && (mouseX <= 150) && (mouseY >=50) && (mouseY <= 150));
}

No comments:

Post a Comment