Created
November 27, 2012 17:24
-
-
Save bakercp/4155666 to your computer and use it in GitHub Desktop.
Barebones Pulse code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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