From 1ace63c0952d77180a257b1596c2a463ec20cfd1 Mon Sep 17 00:00:00 2001 From: Russell Buehling Date: Thu, 27 Apr 2017 22:39:59 -0600 Subject: [PATCH] Create HRT_MNT_P3 Here are proposed changes for the code of the heart rate monitor, the old code could only function in the second version of Processing. The proposed changes now work for the newest version (3.3.2). I figured other individuals could benefit from this and help them get their project done faster and with a lot less headaches. **Side-Note** The only hiccup I encountered in modifying the code and comparing it to the old one's readings was that when it is supposed to be flat-line there is a negative charge that is registered, which was not there when run in Processing v2. --- .../Heart_Rate_Display_Processing/HRT_MNT_P3 | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Software/Heart_Rate_Display_Processing/HRT_MNT_P3 diff --git a/Software/Heart_Rate_Display_Processing/HRT_MNT_P3 b/Software/Heart_Rate_Display_Processing/HRT_MNT_P3 new file mode 100644 index 0000000..baab8e7 --- /dev/null +++ b/Software/Heart_Rate_Display_Processing/HRT_MNT_P3 @@ -0,0 +1,68 @@ +/* +* Here are proposed changes for the code of the heart rate monitor, the old code could only function in the second version of Processing. +* The proposed changes now work for the newest version (3.3.2). +* +* All rights reserved to the original creators. +*/ + +import processing.serial.*; + +Serial myPort; +int xPos = 1; +float height_old = 0; +float height_new = 0; +float inByte = 0; + + +void setup () { + //Window Size + size(1080, 500); + + // List serial ports + println(Serial.list()); + myPort = new Serial(this, Serial.list()[0], 9600); + myPort.bufferUntil('\n'); + + //Background + background(255); + + fill(color(0,0,0)); + text("Heart Rate Monitor v1.0", 10, 10); +} + + +void draw () { + + inByte = map(inByte, 0, 1023, 0, height); + height_new = height - inByte; + line(xPos - 1, height_old, xPos, height_new); + height_old = height_new; + + if (xPos >= width) { + xPos = 0; + background(255); + } + else { + xPos++; + } +} + + +void serialEvent (Serial myPort) { + // get the ASCII string: + String inString = myPort.readStringUntil('\n'); + + if (inString != null) { + // trim off any whitespace: + inString = trim(inString); + + if (inString.equals("!")) { + stroke(0, 0, 255); + inByte = 512; + } + else { + stroke(255, 0, 0); + inByte = float(inString); + } + } +}