Help with a pulse detection func

Yes, that was the missing part, where the magic actually happens. What it is doing is looking for the high spots in the wave form that actually indicate a beat. It computes the time between the last two beats, if there are more than 2 beats detected, and computes a rate based on the time. The last 10 rates are stored in the (global) rate array.

You should be able to simply access the last value in that array to make your decision(s).