Pulse sensor with additional LED

Hi, I’m a teacher and purchased a few of the pulse sensors from adafruit. I downloaded the code from pulsesensor.com and it seems to be working, but I wanted to modify it so that I can add another LED that would turn on if they weren’t in their target heart rate (BPM) range. I set up new variables for the low and high target heart rate and an input pin for the additional LED. Thought I could just put:

if (BPM<targetLow || BPM>targetHigh){
digitalWrite(warningPin, HIGH);
}

in the code somewhere but I can’t figure it out. Please help!

(I attached the code)

Target_heart_rate_pulse_sensor.ino (3.23 KB)

BPM is a volatile int, so you’ll need to get a copy of it first.

// Variables
int BPMcopy;

// at the beginning or end of your loop, add this

noInterrupts();
BPMcopy = BPM;
interrupts();

if (BPMcopy < targetLow || BPMcopy > targetHigh) {
  digitalWrite(warningPin, HIGH);
} else {
  digitalWrite(warningPin, LOW);
}