Re: Drw wave with serial data from Ardino, analyse with Max/msp

Hi llumen, most definitely could do with any help I can get.
This is the project sketch I am starting with for the arduino which records the heartbeat as serial data in the serial monitor;

int ledPin = 13;
int sensorPin = 0;

double alpha = 0.75;
int period = 20;
double change = 0.0;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
static double oldValue = 0;
static double oldChange = 0;
int rawValue =
analogRead(sensorPin);
// smooths wave form using alpha value for level of smoothing
double value = alpha * oldValue
+ (1 – alpha) * rawValue;

digitalWrite(ledPin, (change < 0.0 && oldChange > 0.0));

oldValue = value;
oldChange = change;
delay(period);
}

[attachment=148320,1502]

Attachments:
  1. resized.jpg
Dec 7, 2010 at 6:02pm #193217