The idea is to take the average of the last ten values of BPM. If averages at least 5 values apart have a difference of greater than 2, it will trigger an alarm.

``````int beatarray[10];
int beatarraysum = 0;
int beatarrayavgarray[20];

unsigned long timer
unsigned long timer2

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:
timer = millis()
if (timer > 1500){
if (200 > IBI > 50) {
beatarray[0] = BPM;
for (x = 1; x <= 8; x++){beatarray[x + 1] = beatarray [x]};
for (x = 0; x <= 9; x++){beatarraysum += beatarray[x]};
beatarraysum / 10 = beatarrayavgarray[0];
for (x = 1; x <= 18; x++){beatarrayavgarray[x + 1] = beatarray [x]};
if (for (x = 0; x <= 14; x++){beatarrayavg[x] + 2 <= beatarrayavg[x + 5]{
digitalWrite (vibrate, HIGH);
}

}
}
}
}
``````

When posting code, it’s a good idea to hit Ctr-T in the IDE first, to format it so that it’s readable.
In it’s current form, it’s a mess.

Edit: There are semicolons missing at the end of these:-

``````unsigned long timer
unsigned long timer2
timer = millis()
``````

And also from a bunch of other lines.

“IBI” wasn’t declared.
Neither was “vibrate”, and you didn’t make it an output with ‘pinMode()’ in ‘setup()’.

Even if “IBI” was declared, this is no good:-`(200 > IBI > 50)`You need:-`if((IBI > 50) and (IBI < 200))`
“BPM” wasn’t declared. And is never initialised or modified.

What’s this supposed to do?:-`if (for (x = 0; x <= 14; x++)`

And this:-`beatarraysum / 10 = beatarrayavgarray[0];`
You use “x” everywhere, but never declare it.

At this point, I gave up.

The compiler is the best proof reader - it does not miss anything.

...R

I suggest you do some C/C++ tutorials, then get back to us. We aren't a code-writing service.

Thanks! Sorry about my lack of coding grammar, this is the first time I programmed Arduino in months.

I was able to fix all errors but this one.

OldSteve:
What’s this supposed to do?:-`if (for (x = 0; x <= 14; x++){beatarrayavg[x] + 2 <= beatarrayavg[x + 5]`

That is supposed to basically say if any beatarrayavg is more than 2 lower than a beatarrayavg 5 values in the future, it will trigger an alarm. Unfortunately, it doesn’t work. How can I reformat this?

It means the programmer was either lazy or liked to show off by writing impenetrable code.

...R

What?

``````if (for (x = 0; x <= 14; x++){beatarrayavg[x] + 2 <= beatarrayavg[x + 5]{
digitalWrite (vibrate, HIGH);
}
``````

That is supposed to basically say if any beatarrayavg is more than 2 lower than a beatarrayavg 5 values in the future, it will trigger an alarm. Unfortunately, it doesn’t work. How can I reformat this?

I interpret the above as meaning:-

``````for(int x = 0; x <= 14; x++)
{
if(beatarrayavg[x + 5] - beatarrayavg[x] >= 2)
digitalWrite (vibrate, HIGH);
}
``````

How close is that to what you want? (Nothing in your code ever turns that alarm off again, by the way. I hope that’s what you were aiming for.)

And in future, please stick to one statement per line. If you do that, many of your errors will be immediately obvious. (And we won’t struggle as much trying to understand your code.)

You might want to rethink this next, if you haven’t already done so:-

``````timer = millis()
if (timer > 1500){
``````