Logging An Old Post

Sometimes the hardest thing is making sense of it all… A few weeks ago we were asked to log data collected through a sensor… I was unfortunately unable to log or really understand the process of it. Eventually I just took the code from Mustafa’s Blog edited it with the createWriter function to output a text file. This logged_data file is showing two columns of numbers which I honestly don’t quite understand. I need to run it again and somehow extract patterns from it. For now however this is where I left off a few weeks ago. Does this make me happy? No. The numbers mean nothing as of now to me. But I would like to find a way to understand what makes me happy. What behaviors inform the way I interact with others… or even how my physical self informs my emotional self…

Below is the code I used to out put the file.

import processing.serial.*; // Includes serial library to processing

Serial myPort; // Create object from Serial class
int val = 0; // Data received from the serial port
int preVal = 0; // stores the previous sensor data
int xCoor = 0 ; // X coordinate for drawing line
int preXCoor = 0; // previous x coordinate for drawing line

PrintWriter output;

void setup() {
 size(900, 300); // Stage Size
 background(0); // Stage Color
 output = createWriter("logged_data.txt"); // Create a new file in the sketch directory
 String portName = Serial.list()[0]; // Connecting to port “0″
 myPort = new Serial(this, portName, 9600); // Arduino’s Baudrate
}

void draw() {
 if ( myPort.available() > 0) { // If data is available,
 val = myPort.read(); // read it and store it in val
 xCoor++; // x position increases one pixel
 stroke(#458B00);
 line(preXCoor, preVal, xCoor, val); // Draws a line graph //line(x1, y1, x2 , y2)
 if ( xCoor > 900) { // If line is out of the screen 
 // cleans the screen and starts from zero
 xCoor = 0;
 background(0); // Set background to black
 }
 preXCoor = xCoor; // X coordinate stored, we will use it as previous coordinate in 
 // the next frame.
 preVal = val; // Val stored, we will use it as previous val in the next frame.
 output.println(val); // Write the values to the file
 }
}

void keyPressed() {
 output.flush(); // Writes the remaining data to the file
 output.close(); // Finishes the file
 exit(); // Stops the program
}

Comments are closed.