This program functions as a data visualizer for the Pulse Sensor Serial input is designed to mate with arduino sketch "A_PulseSensor_xx" This code made by Joel Murphy and Yury Gitman in Brooklyn, Summer 2011. interactive features in this version: press 'S' or 's' to take a picture of the data window. (.tif image) Pulse data window will plot pulse 1:1 (ADC value : pixesls) and auto adjust to fit waveform in screen CC Attribution Share-Alike http://creativecommons.org/licenses/by-sa/3.0/us/ */ import processing.serial.*; // this is how we talk to arduino PFont font, rateFont, smallFont; // create font instances Serial port; // create and name the serial port PImage a; int heart = 0; // used to time pulsing of heart graphic with your heart beat int pulseRate = 0; int sum = 0; int avg =0; int [] count = new int [1000]; int counter = 0 ; int temp =0;// used to hold pulse rate value sent from arduino (beats per minute) int Sensor = 0; // used to hold raw sensor data from arduino int HRV; // time between this current beat and the last beat in mS (used for Heart Rate Variability) int Ypos; // used to print the new Pulse Sensor data point int[] pulseY; // used to hold pulse waveform Y positions int[] rateY; int[] pulseX; // used to hold pulse waveform Y positions int[] rateX; // used to hold bpm waveform Y positions // these variables will hold pulse window specs int PulseWindowMin; int PulseWindowMax; int PulseWindowW; int PulseWindowH; int PulseWindowY; int PulseWindowX; int PulseDisplayBaseline = 712; // these variables are used to adjust the pulse window display int PulseOffset = 712; String typing = ""; String name = ""; String subName = ""; String room = ""; String building = ""; int keyCounter = 0;// the max and min will auto adjust if the waveform drifts beyond the screen color eggshell = color(255,253,248); // offwhite color for data display windows color R = color(250,0,0); // red color for datapoints and heart graphic int grey = 80; // grey color for numeric data windows boolean beat = false; // used to advance heart rate graph boolean newRate = false; // used to update heart rate display PrintWriter output = createWriter("newPatient.txt"); void setup() { output.println(+month()+"/"+day()+"/"+year()+", "+hour()+":"+minute()); size(800,800); // Stage size frameRate(100); // refresh rate font = loadFont("Arial-BoldMT-36.vlw"); // font for small text rateFont = loadFont("Arial-BoldMT-80.vlw"); // font for larger text smallFont = loadFont("Arial-BoldMT-14.vlw"); // font for smaller text textFont(font); // set up to print small font textAlign(RIGHT); // referemce points rectMode(CENTER); a = loadImage("vitaband.jpg"); // define the size of the pulse window PulseWindowW = 710; // width of pulse window PulseWindowH = 400; // height of pulse window PulseWindowX = width/2+30; // center X coordinate of pulse window PulseWindowY = height-225; // center Y coordinate of pulse window PulseWindowMin = PulseWindowY - PulseWindowH/2; // top Y position of pulse window PulseWindowMax = PulseWindowY + PulseWindowH/2; // bottom Y position of pulse window pulseY = new int[PulseWindowW+1]; // array to hold Y coordinate of pulse datapoints rateY = new int[320]; // array to hold y coordinate of heart rate datapoints pulseX = new int[PulseWindowW+1]; // array to hold Y coordinate of pulse datapoints rateX = new int[320]; // find and establish contact with the serial port println(Serial.list()); // print a list of available serial ports port = new Serial(this, Serial.list()[2], 115200); // choose the right one in square brackets port.bufferUntil('\n'); // arduino will end each ascii string with a '\n' at the end (carriage return) port.clear(); // flush the serial buffer // set arbitrary initial data position at top of pulse window Ypos = PulseWindowMin; for (int i = 0; i < pulseY.length; i++){ pulseY[i] = PulseWindowMin; } // set the BPM visualizer line to 0 for (int i=0; i 0){ // if a beat happened recently, strokeWeight(8); // make the heart big } smooth(); // draw the heart with two bezier curves image(a, 610, 0, a.width/2, a.height/2); //bezier(width-125,30, width-45,-40, width-25,120, width-125,130); // bezier(width-125,30, width-215,-40, width-225,120, width-125,130); strokeWeight(1); // reset the strokeWeight } // END OF printScreen FUNCTION // original heart design and positioning // bezier(width-150,50, width-70,-20, width-50,140, width-150,150); // bezier(width-150,50, width-230,-20, width-250,140, width-150,150);