Skip to content

Commit 38f55fa

Browse files
committed
Fixed bug when using Arduino Servo library
There was a conflict arising from multiple use of timer between PulseSensor and Servo. Used the __has_include conditional to solve it.
1 parent 142bdea commit 38f55fa

File tree

9 files changed

+17
-17
lines changed

9 files changed

+17
-17
lines changed

examples/PulseSensor_Servo_Motor/PulseSensor_Servo_Motor.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ void loop() {
179179
pulseSensor.outputSample();
180180
// write the latest analog value to the heart servo
181181
moveServo(pulseSensor.getLatestSample());
182-
(signal);
183182
}
184183
}
185184
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=PulseSensor Playground
2-
version=2.0.1
2+
version=2.1.0
33
author=Joel Murphy, Yury Gitman, Brad Needham
44
maintainer=Joel Murphy, Yury Gitman
55
sentence=Support at PulseSensor.com

src/PulseSensorPlayground.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
PulseSensorPlayground::PulseSensorPlayground(int numberOfSensors) {
3131
// Save a static pointer to our playground so the ISR can read it.
32-
#if USE_HARDWARE_TIMER
32+
#if USE_HARDWARE_TIMER
3333
OurThis = this;
3434
#endif
3535

src/PulseSensorPlayground.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef PULSE_SENSOR_PLAYGROUND_H
1919
#define PULSE_SENSOR_PLAYGROUND_H
2020

21+
#include <Arduino.h>
2122
/*
2223
SelectTimer.h will determine if the library supports
2324
hardware timer interrupts or not. If so, it will set
@@ -28,11 +29,12 @@
2829
*/
2930
#include "utility/SelectTimer.h"
3031

32+
3133
/*
3234
Library version number
3335
*/
34-
#define PULSESENSOR_PLAYGROUND_VERSION_STRING "v2.0.0"
35-
#define PULSESENSOR_PLAYGROUND_VERSION_NUMBER 2
36+
#define PULSESENSOR_PLAYGROUND_VERSION_STRING "v2.1.0"
37+
#define PULSESENSOR_PLAYGROUND_VERSION_NUMBER 210
3638

3739
/*
3840
If you wish to perform timing statistics on your non-interrupt Sketch:
@@ -131,6 +133,8 @@
131133
#define SAMPLE_RATE_500HZ 500
132134
#define SAMPLES_PER_SERIAL_SAMPLE 10
133135

136+
137+
134138
class PulseSensorPlayground {
135139
public:
136140
/*
@@ -432,6 +436,7 @@ vvvvvvvv THIS NEEDS MODIFICATION FOR V2 vvvvvvvv
432436
#endif
433437

434438
/*
439+
435440
Sets up the sample timer interrupt for this Arduino Platform
436441
and the pause and resume routines.
437442
*/

src/utility/PulseSensor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
1414
This software is not intended for medical use.
1515
*/
16-
// #ifndef PULSE_SENSOR_PLAYGROUND_H
17-
// #define PULSE_SENSOR_PLAYGROUND_H
18-
// #endif
1916
#include <PulseSensorPlayground.h>
2017

2118
/*

src/utility/PulseSensor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
#ifndef PULSE_SENSOR_H
1717
#define PULSE_SENSOR_H
18-
1918
#include <Arduino.h>
2019

2120
class PulseSensor {

src/utility/PulseSensorTimingStatistics.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
1818
This software is not intended for medical use.
1919
*/
20-
// #ifndef PULSE_SENSOR_PLAYGROUND_H
21-
// #define PULSE_SENSOR_PLAYGROUND_H
22-
// #endif
20+
2321
#include <PulseSensorPlayground.h>
2422

2523
PulseSensorTimingStatistics::PulseSensorTimingStatistics(

src/utility/SelectTimer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
#ifndef SELECT_TIMER_H
6363
#define SELECT_TIMER_H
6464

65-
6665
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_RP2040)\
6766
|| defined(ARDUINO_SAM_DUE) || defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_ESP32)\
6867
|| defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_ESP8266)

src/utility/TimerHandler.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
the platform detected by PulseSensorPlaygroundSetupInterrupt().
4747
*/
4848
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATtiny85__)
49-
#if defined Servo_h
49+
#if __has_include (<Servo.h>)
50+
#warning "Detected Servo library in TimerHandler.h"
5051
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
5152
#ifndef TIMER_VECTOR
5253
#define TIMER_VECTOR
@@ -86,12 +87,14 @@
8687
#endif
8788
#endif
8889
#endif
90+
// #endif
8991

9092
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
91-
#if defined Servo_h
93+
#if __has_include (<Servo.h>)
94+
#warning "Detected Servo library in TimerHandler.h"
9295
#ifndef TIMER_VECTOR
9396
#define TIMER_VECTOR
94-
ISR(TIMER1_COMPA_vect)
97+
ISR(TIMER2_COMPA_vect)
9598
{
9699
DISABLE_PULSE_SENSOR_INTERRUPTS; // disable interrupts while we do this
97100

@@ -103,7 +106,7 @@
103106
#else
104107
#ifndef TIMER_VECTOR
105108
#define TIMER_VECTOR
106-
ISR(TIMER2_COMPA_vect)
109+
ISR(TIMER1_COMPA_vect)
107110
{
108111
DISABLE_PULSE_SENSOR_INTERRUPTS; // disable interrupts while we do this
109112

0 commit comments

Comments
 (0)