// *** Processing code ***
// -------------------
//
// -Checks for keypress, send Serial.
//
import processing.serial.*;
Serial port; // Create place in memory for serial comm
void setup() {
size(600, 600);
fill(0,0,0); // set fill color to black
println(Serial.list()); // print out available serial ports
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[2], 9600);
}
void draw() {
rect(0, 0, width, height); // rectangle covers (clears) screen
imageMode(CENTER);
}
void keyPressed() {
if (key == 49) { // Key code for the "1" key
fill(255,0,0); // set fill to Red
port.write(49);
println(49);
} else if (key == '2') {
port.write(50);
println(50);
fill(0,255,0); // set fill to Green
} else {
fill(120,150,150);
}
}
void keyReleased() {
port.write(0);
}
|