Professional Documents
Culture Documents
Sketch 160602b
Sketch 160602b
Sketch 160602b
*;
Serial port;
int word;
byte[] inByte;
int count = 0;
int flag = 0;
void setup(){
println(Serial.list()[1]);
String arduinoPort = Serial.list()[1];
port = new Serial(this, arduinoPort, 9600); // Arduino
size(480,320);
noLoop();
}
void draw(){
inByte = port.readBytes();
port.readBytes(inByte);
if (inByte != null) {
String myString = new String(inByte);
println(myString+"\n");
}
/*
background(255);
for(int i = 0; i< 225; i++){
print(int(inByte[i]) + " ");
fill(int(inByte[i])*2.4);
rect((i%15)*10, i/15*10 , 10, 10);
}
print("\n");
for(int i = 0; i< 225; i++){
print(int(inByte[i+225]) + " ");
fill(int(inByte[i+225])*2.4);
rect((i%15)*10 + 150, i/15*10 , 10, 10);
}
count = 0;
*/
}
/*
void serialEvent(Serial port){
word = port.read();
if(char(word) == 'A'){
flag = 1;
}
if(flag == 1){
if(char(word) == 'Z'){
redraw();
flag = 0;
}else{
inByte[count++] = word;
}
port.readBytesUntil(int('Z'), inByte);
flag = 0;
redraw();
}
// print(word+" ");
}
*/
// delay(10);
// inByte=port.read();
// if (inByte == 1){
// count = 0;
// noLoop();
// }