import processing.serial.*; Serial myPort; int xPos = 5; // horizontal position of the graph float oldHeartrateHeight = 0; // for storing the previous reading void setup () { size(600, 400); frameRate(25); println(Serial.list()); myPort = new Serial(this, "COM3", 9600); background(0); } void draw () { text("0bpm---",1,200); text("72bpm---",1,200-27); //27 is the mapped value of 72 (approx.) //text("100bpm---",1,200-39); text("120bpm---",1,200-47); } void serialEvent (Serial myPort) { String inString = myPort.readStringUntil('\n'); if (inString != null) { inString = trim(inString); println(inString); int currentHeartrate = int(inString); float heartrateHeight = map(currentHeartrate, 0, 1023, 0, 400); stroke(0,255,0); line(xPos - 5,(height/2)-oldHeartrateHeight, xPos, (height/2)-heartrateHeight); oldHeartrateHeight = heartrateHeight; if (xPos >= width) { xPos = 0; background(0); } else { xPos+=5; } } }