Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Amplifying a certaing part of a visualization

$
0
0
Hi all (and merry christmas),

I need help. Ive built a heartbeat sensor in Arduino and am now trying to visualize it in Processing. Below is an image of the Arduino input being visualized in Processing:
 



Now my problem is that the heartbeats are only vaguely depicted, so I need to find a way to "amplify" the peaks, so the heartbeats can be more easily read. Like this guy has done. If theres a need for more info or if you have any questions just ask! For more info on the project: http://www.ddlab.dk/i-found-my-pulse/.

Below is the Processing Code I am using, its just a slight rewrite of the Basic Graphing Tutorial:
  1. /*
  2.  Graph
  3.  A simple example of communication from the Arduino board to the computer:
  4.  the value of analog input 0 is sent out the serial port.  We call this "serial"
  5.  communication because the connection appears to both the Arduino and the
  6.  computer as a serial port, even though it may actually use
  7.  a USB cable. Bytes are sent one after another (serially) from the Arduino
  8.  to the computer.
  9.  You can use the Arduino serial monitor to view the sent data, or it can
  10.  be read by Processing, PD, Max/MSP, or any other program capable of reading 
  11.  data from a serial port.  The Processing code below graphs the data received 
  12.  so you can see the value of the analog input changing over time.
  13.  
  14.  The circuit:
  15.  Any analog input sensor is attached to analog in pin 0.
  16.   
  17.  created 2006
  18.  by David A. Mellis
  19.  modified 9 Apr 2012
  20.  by Tom Igoe and Scott Fitzgerald
  21.  
  22.  This example code is in the public domain.

  23.  http://www.arduino.cc/en/Tutorial/Graph
  24.  */

  25. import processing.serial.*;
  26.  
  27.  Serial myPort;        // The serial port
  28.  int xPos = 1;         // horizontal position of the graph
  29.  
  30.  void setup () {
  31.  // set the window size:
  32.  size(1400, 500);      
  33.  
  34.  // List all the available serial ports
  35.  println(Serial.list());
  36.  // I know that the first port in the serial list on my mac
  37.  // is always my  Arduino, so I open Serial.list()[0].
  38.  // Open whatever port is the one you're using.
  39.  myPort = new Serial(this, Serial.list()[0], 9600);
  40.  // don't generate a serialEvent() unless you get a newline character:
  41.  myPort.bufferUntil('\n');
  42.  // set inital background:
  43.  background(0);
  44.  }
  45.  void draw () {
  46.  // everything happens in the serialEvent()
  47.  }
  48.  
  49.  void serialEvent (Serial myPort) {
  50.  // get the ASCII string:
  51.  String inString = myPort.readStringUntil('\n');
  52.  
  53.  if (inString != null) {
  54.  // trim off any whitespace:
  55.  inString = trim(inString);
  56.  // convert to an int and map to the screen height:
  57.  float inByte = float(inString); 
  58.  inByte = map(inByte, 0, 1023, 0, height);
  59.  
  60.  // draw the line:
  61.  stroke(216, 24, 24);
  62.  line(xPos, height, xPos, height - inByte);
  63.  
  64.  // at the edge of the screen, go back to the beginning:
  65.  if (xPos >= width) {
  66.  xPos = 0;
  67.  background(0); 
  68.  } 
  69.  else {
  70.  // increment the horizontal position:
  71.  xPos++;
  72.  }
  73.  }
  74.  }

Regards,
René 

Viewing all articles
Browse latest Browse all 1768

Trending Articles