diff --git a/BrainGrapher.pde b/BrainGrapher.pde index 6a9c862..6f6d868 100644 --- a/BrainGrapher.pde +++ b/BrainGrapher.pde @@ -31,8 +31,13 @@ void setup() { // Set up serial connection println("Find your Arduino in the list below, note its [index]:\n"); - println(Serial.list()); - serial = new Serial(this, Serial.list()[0], 9600); + + for (int i = 0; i < Serial.list().length; i++) { + println("[" + i + "] " + Serial.list()[i]); + } + + // Put the index found above here: + serial = new Serial(this, Serial.list()[5], 9600); serial.bufferUntil(10); // Set up the ControlP5 knobs and dials @@ -78,7 +83,7 @@ void setup() { graph = new Graph(0, 0, width, height / 2); // Set yup the connection light - connectionLight = new ConnectionLight(width - 98, 10, 20); + connectionLight = new ConnectionLight(width - 105, 10, 20); } void draw() { @@ -110,7 +115,12 @@ void draw() { void serialEvent(Serial p) { // Split incoming packet on commas // See https://github.com/kitschpatrol/Arduino-Brain-Library/blob/master/README for information on the CSV packet format - String[] incomingValues = split(p.readString(), ','); + + String incomingString = p.readString().trim(); + print("Received string over serial: "); + println(incomingString); + + String[] incomingValues = split(incomingString, ','); // Verify that the packet looks legit if (incomingValues.length > 1) { @@ -118,17 +128,22 @@ void serialEvent(Serial p) { // Wait till the third packet or so to start recording to avoid initialization garbage. if (packetCount > 3) { + for (int i = 0; i < incomingValues.length; i++) { - int newValue = Integer.parseInt(incomingValues[i].trim()); + String stringValue = incomingValues[i].trim(); + + int newValue = Integer.parseInt(stringValue); // Zero the EEG power values if we don't have a signal. // Can be useful to leave them in for development. - if ((Integer.parseInt(incomingValues[0]) == 200) && (i > 2)) newValue = 0; + if ((Integer.parseInt(incomingValues[0]) == 200) && (i > 2)) { + newValue = 0; + } channels[i].addDataPoint(newValue); } } - } + } } diff --git a/Monitor.pde b/Monitor.pde index 78b7fbc..80a1ce4 100644 --- a/Monitor.pde +++ b/Monitor.pde @@ -18,17 +18,17 @@ class Monitor { backgroundColor = color(255); // Create GUI - showGraph = controlP5.addCheckBox("showGraph" + sourceChannel.name, x + 6, y + 18); + showGraph = controlP5.addCheckBox("showGraph" + sourceChannel.name, x + 16, y + 32); showGraph.addItem("GRAPH" + sourceChannel.name, 0); - showGraph.activate(0); + showGraph.activate(1); showGraph.setColorForeground(sourceChannel.drawColor); - showGraph.setColorActive(color(0)); - showGraph.setColorBackground(color(180)); + showGraph.setColorActive(color(180)); + showGraph.setColorBackground(color(0)); toggle = showGraph.getItem(0); toggle.setLabel("GRAPH"); - label = new Textlabel(controlP5, sourceChannel.name.toUpperCase(), x + 2, y + 5); + label = new Textlabel(controlP5, sourceChannel.name.toUpperCase(), x + 12, y + 15); label.setColorValue(0); } @@ -70,7 +70,7 @@ class Monitor { // Draw the checkbox matte noStroke(); - fill(255, 150); + fill(240, 150); rect(10, 10, w - 20, 40); popMatrix();