-1
#include "pulse-sensor-arduino.h"
#include "Arduino.h"
#define PulseSensorbegin

int pulsePin = 0;                
int blinkPin = 13;                
int fadePin = 5;                 
int fadeRate = 0;                 
volatile int BPM;                  
volatile int Signal;                
volatile int IBI = 600;            

volatile boolean QS = false;        

void setup(){

  pinMode(blinkPin,OUTPUT);   
  pinMode(fadePin,OUTPUT);          
  Serial.begin(115200);           

  PulseSensorbegin();

}


void loop() {

   sendDataToProcessing('S', Signal);     
   if (QS == true) 
   {        
       fadeRate = 255;                  
       sendDataToProcessing('B',BPM);   
       sendDataToProcessing('Q',IBI);  
       QS = false;                      
   }

   ledFadeToBeat();

   delay(5000);                             
}


void ledFadeToBeat(){

    fadeRate -= 15;                         
    fadeRate = constrain(fadeRate,0,255);   
    analogWrite(fadePin,fadeRate);          
  }


void sendDataToProcessing(char symbol, int data ){

    Serial.print(symbol);                
    Serial.println(data);                
  }

/// my ccp program

#include "pulse-sensor-arduino.h"

volatile int rate[10];                        
volatile unsigned long sampleCounter = 0;     
volatile unsigned long lastBeatTime = 0;      
volatile int P =512;                         
volatile int T = 512;                        
volatile int thresh = 512;                    
volatile int amp = 100;                       
volatile boolean firstBeat = true;           
volatile boolean secondBeat = false;          
volatile boolean Pulse = false;              
volatile int pulsePin;

volatile int PulseSensor::IBI = 600;          
volatile int PulseSensor::BPM;                
volatile int PulseSensor::Signal;             
volatile boolean PulseSensor::QS = false;     
void PulseSensor::begin(int pPin)
{
  pinMode(pulsePin, INPUT);
  pulsePin = pPin;


  TCCR1A = 0x00;
  TCCR1B = 0x0C;  
  OCR1A = 0x7C;  
  TIMSK1 = 0x02;
  sei();             
}


ISR(TIMER1_COMPA_vect)

{                        
  cli();                                      
  PulseSensor::Signal = analogRead(pulsePin);             
  sampleCounter += 2;                         
  int N = sampleCounter - lastBeatTime;       


  if(PulseSensor::Signal < thresh && N > (PulseSensor::IBI/5)*3)
{       
    if (PulseSensor::Signal < T){                        
      T = PulseSensor::Signal;                         
    }
  }

  if(PulseSensor::Signal > thresh && PulseSensor::Signal > P)
{          
    P = PulseSensor::Signal;                             
  }                                       


  if (N > 250){                                  
    if ( (PulseSensor::Signal > thresh) && (Pulse == false) && (N > (PulseSensor::IBI/5)*3) )
    {        
      Pulse = true;                              
      PulseSensor::IBI = sampleCounter - lastBeatTime;        
      lastBeatTime = sampleCounter;              

      if(secondBeat){                        
        secondBeat = false;                 
        for(int i=0; i<=9; i++){             
          rate[i] = PulseSensor::IBI;                      
        }
      }

      if(firstBeat){                         
        firstBeat = false;                   
        secondBeat = true;                   
        sei();                               
        return;                              
      }   



      word runningTotal = 0;                    

      for(int i=0; i<=8; i++){                
        rate[i] = rate[i+1];                  
        runningTotal += rate[i];             
      }

      rate[9] = PulseSensor::IBI;                          
      runningTotal += rate[9];               
      runningTotal /= 10;                      
      PulseSensor::BPM = 60000/runningTotal;              
      PulseSensor::QS = true;                              
    }                       
  }

  if (PulseSensor::Signal < thresh && Pulse == true){   
    Pulse = false;                        
    amp = P - T;                           
    thresh = amp/2 + T;                    
    P = thresh;                          
    T = thresh;
  }

  if (N > 2500){                           
    thresh = 512;                         
    P = 512;                              
    T = 512;                               
    lastBeatTime = sampleCounter;                
    firstBeat = true;                      
    secondBeat = false;                    
  }

  sei();                                 
} 

//my header programing

#ifndef PULSE_SENSOR_ARDUINO_H
#define PULSE_SENSOR_ARDUINO_H

#include "Arduino.h"

class PulseSensor
{
public:
  static void begin(int pulsePin);

  static volatile int BPM;          
  static volatile int Signal;        
  static volatile int IBI;           
  static volatile boolean QS;        
};

#endif 
7
  • 2
    "Data dump" is a bad way to ask questions. Telling us where you got the error message and what you have done to try to fix it would be a good start. Commented Feb 6, 2015 at 9:13
  • i got the error on PulseSensorbegin(); in the void setup() i got an error message like this ///expected primary-expression before ')' token Error compiling Commented Feb 6, 2015 at 9:25
  • I noted that "ifndef" should be "#ifndef" then realised that the editor "eats" the "#" symbol and that it IS in your code. Commented Feb 6, 2015 at 9:31
  • 1
    Presumably PulseSensorbegin() is actually meant to be PulseSensor::begin()? Commented Feb 6, 2015 at 12:31
  • 1
    @KarthiKeyan The line in setup() which says PulseSensorbegin() isn't doing that though. It's probably actually causing your error because it's missing the scope operator (::). Commented Feb 6, 2015 at 13:39

1 Answer 1

4

At the top of your program you have this:

#define PulseSensorbegin

which defines PulseSensorbegin as nothing

Then later you have:

PulseSensorbegin();

which the pre-processor turns into:

();

which is where the error is occurring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.