Skip to content

Instantly share code, notes, and snippets.

@galyaobe galyaobe/WavePlotter.pde
Last active May 14, 2016

Embed
What would you like to do?
Wave Plotter Program
void serialEvent(Serial myPort) {
String ardIn = myPort.readStringUntil(linefeed);
if (ardIn != null) {
ardIn = trim(ardIn);
input = float(split(ardIn, ','));
printArray(input[0]);
if (counter%4 == 0 && counter !=0) {
println("DIG EV");
digitalEvent=true;
counter++;
} else {
println("ANA EV");
analogEvent=true;
counter++;
}
delay(200);
}
}
void eventHappen() {
if (analogEvent) {
for (int j = 1; j < n; j++)
analog[j-1] = analog[j];
for (int i = 0; i < 1; i++)
analog[n-1] = input[i];
analogEvent=false;
}
if (digitalEvent) {
for (int j = 1; j < n; j++)
digital[j-1] = digital[j];
for (int i = 0; i < 1; i++)
digital[n-1] = input[i];
digitalEvent=false;
}
}
//The EEGen Project
//Created by Galya Oberman
//theeegenproject.wordpress.com
import processing.serial.*;
PGraphics canvas;
Serial myPort;
int linefeed = 10;
float[] input = new float[1]; //temporary store for values
float[] digital = new float[200];
float[] analog = new float [200]; //2D array for point plotting
int n = 200; //number of points onscreen at a time
int counter = 1;
boolean analogEvent = false;
boolean digitalEvent = false;
void setup() {
size(1000, 250);
canvas = createGraphics(1000, 250);
canvas.beginDraw();
canvas.endDraw();
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(linefeed);
println(Serial.list());
//can change to initialize to fix incoming wave/line onscreen
for (int j = 1; j < n; j++)
analog[j] = 450;
}
void draw() {
background(255);
smooth();
stroke(102, 102, 255);
strokeWeight(1); // wave midlines
line(0, 125, 1000, 125);
stroke(255, 51, 51);
strokeWeight(4); // wave boundaries
line(0, 0, 1000, 0);
line(0, 249, 1000, 249);
stroke(0);
strokeWeight(2);
noFill();
eventHappen();
translate(0, -50);
beginShape();
for (int j = 0; j < n; j++) {//plot all points for whole wave
vertex(j*5, (1333 - analog[j])/5);
}
endShape();
}
void keyPressed() {
if (key == 's' || key == 'S') {
save("C:/Users/Galya's/Desktop/The EEGen Program/WaveMatrixOneInputNew/data/output/INITIALS-" + month() + "-" + day() + "-" + hour() + "-" + minute() + "-" + second() + ".tif"); //change to own file path
println((millis()/1000.0) + " seconds: SCREENSHOT");
}
}
@galyaobe

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.