Skip to content

Instantly share code, notes, and snippets.

@bakercp
Created November 27, 2012 17:24
Show Gist options
  • Save bakercp/4155666 to your computer and use it in GitHub Desktop.
Save bakercp/4155666 to your computer and use it in GitHub Desktop.
Barebones Pulse code.
/*
THIS PROGRAM WORKS WITH PulseSensorAmped_Arduino-xx ARDUINO CODE
*/
import processing.serial.*;
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
void setup() {
size(700, 600); // Stage size
frameRate(60);
// 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()[0], 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);
// just print values to the console
println("BPM=" + BPM);
println("IBI=" + IBI);
println("Sensor=" + Sensor);
println("-----------------");
// TODO: your logical if/then statements would go here
} //end of draw loop
void serialEvent(Serial port){
String inData = port.readStringUntil('\n');
inData = trim(inData); // cut off white space (carriage return)
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
}
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment