Skip to content

Instantly share code, notes, and snippets.

@AiHiro
Created January 30, 2017 13:23
Show Gist options
  • Save AiHiro/e0ea129b73291ad541b7d53ebb63032c to your computer and use it in GitHub Desktop.
Save AiHiro/e0ea129b73291ad541b7d53ebb63032c to your computer and use it in GitHub Desktop.
import processing.serial.*;
Serial port;
int y0 = 200;
boolean draw_flag = true;
int t = 0;
int data;
void draw_axis() {
stroke(0);
line(0, y0, width, y0);
}
void plot_data(int data, char c) {
if (c == 'r') stroke(255, 0, 0);
strokeWeight(2);
point(t, y0 - map(data, 0, 255, 0, y0));
strokeWeight(1);
}
void setup() {
size(500, 230);
port = new Serial( this, "/dev/cu.usbmodem1421", 9600);
}
void draw() {
if (draw_flag) {
if (t == 0) {
background(0);
draw_axis();
}
plot_data(data, 'r');
t = (t+1) % width;
println( data );
}
}
void mouseClicked() {
draw_flag = !draw_flag;
}
void serialEvent(Serial p) {
data = port.read();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment