Created
May 1, 2015 12:36
-
-
Save zigen/a11ac44d82846070e0c0 to your computer and use it in GitHub Desktop.
arduinoとシリアル通信
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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