Hey Guys,
I'm new to this forum, but I will try to be as clear as I possibly can. I need your help.
I'm trying to make a servo that is controlled by my heartrate, before I tried this I programmed a simple BPM sensor to print my heart rate in the serial monitor. I basically copied and slightly modified the code to work, but Arduino is messing with me and telling me it expects an initializer before my 'int'. I have tried every intitializer I can think of and it keeps giving me this error.
Now you know what I'm trying to create, here is my code:
#include <Servo.h> // Includes the Servo library
#include <PulseSensorPlayground.h> // Includes the library for reading a heartrate
#define USE_ARDUINO_INTERRUPTS true // Set-up for low-level interrupts for BPM math
Servo myServo; // Creates an object that uses the servo library
PulseSensorPlayground pulseSensor // Creates an object that uses the PulseSensorPlayground library
int PulseWire = 0; // The heart rate sensor will be read via A0
int Threshold = 550; // Determine the signal to count as a beat for more accurate reading
int val;
void setup() {
Serial.begin(9600);
pulseSensor.analogInput(PulseWire);
pulseSensor.setThreshold(Threshold);
myServo.attach(9); // The servo will be attached to D9
// Double-check the "pulseSensor" object was created and "began" seeing a signal.
if (pulseSensor.begin()) {
Serial.println("BPM ready"); //This prints one time at Arduino power-up, or on Arduino reset.
}
}
void loop() {
int BPM = pulseSensor.getBeatsPerMinute(); // Asks for BPM
val = analogRead(PulseWire);
val = map(val, 0, 220, 0, 180); // Maps the value so we can use it on the Servo, 220 might be 1023
myServo.write(val);
delay(15);
}
This is the error code it gives me:
Arduino: 1.8.5 (Mac OS X), Board: "Arduino/Genuino Uno"
Stomme_int:8: error: expected initializer before 'int'
int PulseWire = 0; // The heart rate sensor will be read via A0
^
/Users/Niels/Library/Mobile Documents/com~apple~CloudDocs/Windesheim/Engineering/MINOR 'creative engineering'/Arduino/Servo control/Servo control with BPM/Stomme_int/Stomme_int.ino: In function 'void setup()':
Stomme_int:15: error: 'pulseSensor' was not declared in this scope
pulseSensor.analogInput(PulseWire);
^
Stomme_int:15: error: 'PulseWire' was not declared in this scope
pulseSensor.analogInput(PulseWire);
^
/Users/Niels/Library/Mobile Documents/com~apple~CloudDocs/Windesheim/Engineering/MINOR 'creative engineering'/Arduino/Servo control/Servo control with BPM/Stomme_int/Stomme_int.ino: In function 'void loop()':
Stomme_int:27: error: 'pulseSensor' was not declared in this scope
int BPM = pulseSensor.getBeatsPerMinute(); // Asks for BPM
^
Stomme_int:28: error: 'PulseWire' was not declared in this scope
val = analogRead(PulseWire);
^
exit status 1
expected initializer before 'int'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Thanx in advance