Skip to content

Instantly share code, notes, and snippets.

@zigen
Created May 1, 2015 12:36
Show Gist options
  • Save zigen/a11ac44d82846070e0c0 to your computer and use it in GitHub Desktop.
Save zigen/a11ac44d82846070e0c0 to your computer and use it in GitHub Desktop.
arduinoとシリアル通信
import processing.serial.*;
boolean isEmit = false;
Serial arduino;
void setup() {
println(Serial.list());
arduino = new Serial(this, Serial.list()[5], 9600);
arduino.write(0);
}
void draw() {
if (isEmit) {
background(255);
} else {
background(0);
}
if (arduino.available() > 0 ) {
byte[] inBuffer = new byte[4];
while (arduino.available () > 0) {
inBuffer = arduino.readBytes();
arduino.readBytes(inBuffer);
if (inBuffer != null) {
String myString = new String(inBuffer);
println(myString);
}
}
}
}
}
void mouseClicked() {
isEmit = !isEmit;
arduino.write(isEmit ? 1 : 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment