strokeWeight(1); // reset the strokeWeight for next time
// PRINT THE DATA AND VARIABLE VALUES
fill(eggshell); // get ready to print text
text("Pulse Sensor Amped Visualizer 1.1",245,30); // tell them what you are
text("IBI " + IBI + "mS",600,585); // print the time between heartbeats in mS
text(BPM + " BPM",600,200); // print the Beats Per Minute
text("Pulse Window Scale " + nf(zoom,1,2), 150, 585); // show the current scale of Pulse Window
// DO THE SCROLLBAR THINGS
scaleBar.update (mouseX, mouseY);
scaleBar.display();
//
} //end of draw loop
//.............................................scalebar (name of file)............................................................................................................
/**
THIS SCROLLBAR OBJECT IS BASED ON THE ONE FROM THE BOOK "Processing" by Reas and Fry
*/
class Scrollbar{
int x,y; // the x and y coordinates
float sw, sh; // width and height of scrollbar
float pos; // position of thumb
float posMin, posMax; // max and min values of thumb
boolean rollover; // true when the mouse is over
boolean locked; // true when it's the active scrollbar
float minVal, maxVal; // min and max values for the thumb
Scrollbar (int xp, int yp, int w, int h, float miv, float mav){ // values passed from the constructor
x = xp;
y = yp;
sw = w;
sh = h;
minVal = miv;
maxVal = mav;
pos = x - sh/2;
posMin = x-sw/2;
posMax = x + sw/2; // - sh;
}
// updates the 'over' boolean and position of thumb
void update(int mx, int my) {
if (over(mx, my) == true){
rollover = true; // when the mouse is over the scrollbar, rollover is true
} else {
rollover = false;
}
if (locked == true){
pos = constrain (mx, posMin, posMax);
}
}
// locks the thumb so the mouse can move off and still update
void press(int mx, int my){
if (rollover == true){
locked = true; // when rollover is true, pressing the mouse button will lock the scrollbar on
}else{
locked = false;
}
}
// resets the scrollbar to neutral
void release(){
locked = false;
}
// returns true if the cursor is over the scrollbar
strokeWeight(8); // make the scale dot bigger if you're on it
}
ellipse(pos, y, sh, sh); // create the scaling dot
strokeWeight(1); // reset strokeWeight
}
// returns the current value of the thumb
float getPos() {
float scalar = sw / sw; // (sw - sh/2);
float ratio = (pos-(x-sw/2)) * scalar;
float p = minVal + (ratio/sw * (maxVal - minVal));
return p;
}
}
//...........................................serialevent (name of file)..........................................................................................................
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
beat = true; // set beat flag to advance heart rate graph
heart = 20; // begin heart image 'swell' timer
}
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