hello,
I am stuck trying to figure out how to get the rect to light up when one of the keyboard buttons is pressed but they all seem light up when a key is pressed, i have coded this in processing 2.2, please excuse my bad coding as i am not familiar with java.
thanks
import processing.serial.*;
Serial myPort;
int val;
void setup()
{
size(350, 330);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
if (keyPressed) {
if (key == 'w' || key == 'W') {
fill(0);
myPort.write('W');
}
} else {
fill(255);
stop();
}
rect(150, 90, 50, 50);
if (keyPressed) {
if (key == 'a' || key == 'A') {
fill(0);
myPort.write('A');
}
} else {
fill(255);
stop();
}
rect(80, 160, 50, 50);
if (keyPressed) {
if (key == 's' || key == 'S') {
fill(0);
myPort.write('S');
}
} else {
fill(255);
stop();
}
rect(150, 160, 50, 50);
if (keyPressed) {
if (key == 'd' || key == 'D') {
fill(0);
myPort.write('D');
}
} else {
fill(255);
stop();
}
rect(220, 160, 50, 50);
}
void stop(){
myPort.write('L');
return;
}