Ok, I am trying to get a face to jitter when a button is pressed on the arduino. Unfortunately I am encountering some problems.
Here is my Arduino code:
Code:const int buttonPin = 12;
int buttonState = 0;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
Serial.write(66); }else{
Serial.write(97);
}
}
I do not believe there is any problem with this code or the circuit because when I open the Arduino serial monitor I get lowercase a's and when I press the button these a's are replaced with capital B's.
And here is the processing code for that Arduino sketch:
Code:import processing.serial.*;
Serial myPort;
int inByte;
void setup(){
size(400, 400);
String portName = Serial.list()[2];
myPort = new Serial(this, portName, 9600);
}
void draw() {
fill(0);
rect(100,100,200,200);
fill(255);
rect (140, 120, 45, 45);
rect (220, 120, 45, 45);
rect (140, 250, 120, 30);
fill(255);
if (myPort.available() > 0) {
inByte = myPort.read();
if (inByte == 'B') {
translate(random(-20, 20),random(-20,20));
}
}
}
This code runs fine except when a button is pressed on the arduino the face does not do anything. I know it is not a problem with the serial port because I was able to get the simple read program from the library working. This leads me to think it may be something with drawing/animation, but I'm not sure. Anybody have any suggestions?