Pixels & Data

This is serial date coming from a pulse sensor in Arduino affecting the image tint.
Iv’e also used this data with processing to set an alarm when the pulse gets too high, as part of a Pcomp project.

Screen Shot 2013-11-25 at 11.25.52 AM

 

 

 

 

 

 

 

 

 

 

 

Heartalarm


https://vimeo.com/77601603

 

 

 

This is the code (based on the original code that comes with the pulse sensor):

import processing.serial.*;
PFont font;
Serial port;
int Sensor; // HOLDS PULSE SENSOR DATA FROM ARDUINO
int IBI; // HOLDS TIME BETWEN HEARTBEATS FROM ARDUINO
int BPM; // HOLDS HEART RATE VALUE FROM ARDUINO
int[] rate; // USED TO POSITION BPM DATA WAVEFORM

//float zoom; // USED WHEN SCALING PULSE WAVEFORM TO PULSE WINDOW
float offset; // USED WHEN SCALING PULSE WAVEFORM TO PULSE WINDOW

boolean beat = false; //set when a heart beat is detected, then cleared when the BPM graph is advanced
float val = 0.0;
float r;

void setup() {
size(640, 480,P3D); //Stage size
frameRate(100);
font = loadFont(“Arial-BoldMT-24.vlw”);
textFont(font);
rectMode(CENTER);
textAlign(CENTER);

// GO FIND THE ARDUINO
println(Serial.list()); // print a list of available serial ports
// choose the number between the [] that is connected to the Arduino
port = new Serial(this, Serial.list()[8], 115200); // make sure Arduino is talking serial at this baud rate
port.clear(); // flush buffer
port.bufferUntil(‘\n’); // set buffer full flag on receipt of carriage return
}

void draw() {
background(0);
text(BPM + ” BPM”,100,50); // print the Beats Per Minute

fill(255);

if (beat){
sphere(r);
r= random(BPM*0.89, BPM*0.9);}
}
void serialEvent(Serial port) {

String inData = port.readStringUntil(‘\n’);
inData = trim(inData); // cut off white space (carriage return)

println(inData);

if (inData != null && inData.length() > 1) {

if (inData.charAt(0) == ‘S’) { // leading ‘S’ for sensor data
inData = inData.substring(1); // cut off the leading ‘S’
Sensor = int(inData); // convert the string to usable int
}
if (inData.charAt(0) == ‘B’) { // leading ‘B’ for BPM data
inData = inData.substring(1); // cut off the leading ‘B’
BPM = int(inData); // convert the string to usable int
beat = true; // set beat flag to advance heart rate graph
val = val + 0.02;
}
if (inData.charAt(0) == ‘Q’) { // leading ‘Q’ means IBI data
inData = inData.substring(1); // cut off the leading ‘Q’
IBI = int(inData); // convert the string to usable int
}
}
}

Leave a Comment.