Continuing from the last sketch, I’ve done the same thing but in a different manner. I still have Processing generate a square and when the mouse moves over the square it lights a LED on the Arduino, just as before. Although this time, the only code on the Arduino is the “Standard Firmata” sketch.
Processing interfaces with Firmata to control the pins as one would in the Arduino IDE. So instead of sending for “H” or “L” on the serial port, we send arduino.digitalWrite(ledPin, Arduino.HIGH) or arduino.digitalWrite(ledPin, Arduino.LOW) on the serial port. See the video below for examples, and code at the bottom.
Basic Processing to Arduino Communications part 02 from Morgellon on Vimeo.
My first impressions of Firmata and why one would use it:
First impressions of Firmata and why one would NOT use it.
Processing Code
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin = 12;
void setup()
{
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0]); // v2
//arduino = new Arduino(this, Arduino.list()[0], 57600); // v1
arduino.pinMode(ledPin, Arduino.OUTPUT);
size(200, 200);
noStroke();
frameRate(10);
}
void draw()
{
background (255);
if (mouseOverRect() == true) { //if mouse over square
fill(242, 204, 47); //yellow color
arduino.digitalWrite(ledPin, Arduino.HIGH); //LED on
} else {
fill(0); //black color
arduino.digitalWrite(ledPin, Arduino.LOW); //LED off
}
rect(50, 50, 100, 100); //draws the square
}
boolean mouseOverRect() {
return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}
6-2-2010 @ 08:06
[...] http://arduino.cc/en/Tutorial/Dimmer http://dailyduino.com/archives/483 http://dailyduino.com/archives/487 [...]