Diverse use of the pulse sensor

I did a simple example of getting data from the pulse sensor and then using the value of the heartbeat value as the size of the radius of the ellipses. The color is also determined using the heartbeat value. I thought it was a little funny when I jokingly put the pulse sensor against my speakers. It was creating a visual representation of the beat of the music.

This is my code for Processing:

import java.lang.String;
import processing.serial.*;

Serial myPort;
int lf = 10;

String heartbeat;
float beat;
String duration;

void setup() {
  fullScreen();
  ellipseMode(CENTER);
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil(lf);
  
  
}

void draw() {
  background(0);
  
  text("received: " + heartbeat, 10,50);
  ellipse(width/2, height/2, beat*3, beat*3);

}

void serialEvent(Serial p) {
  String temp = p.readString();
  if(temp.charAt(0) == 'Q'){
    duration = temp.substring(1);
    println(duration);
  }
  else if(temp.charAt(0) == 'B'){
    heartbeat = temp.substring(1);
    beat = map(float(heartbeat), 0, width, 0, height);
    fill(beat, random(0, 255), random(0, 255));
  }
}

 

Leave a Reply