Hello,
I get the error “pulseIn was not declared in this scope” for my previously worked code. How can I solve this problem?
Here is the code. This is my cpp-file for hc-sr04 sensor.
#include "application.h"
#include "hc_sr04.h"
#include "math.h"
HC_SR04::HC_SR04( uint8_t pin_trigger, uint8_t pin_echo) {
_pin_trigger = pin_trigger;
_pin_echo = pin_echo;
}
void HC_SR04::begin(void) {
// set up the pins!
pinMode(_pin_trigger, OUTPUT);
pinMode(_pin_echo, INPUT);
// set defined state
digitalWrite(_pin_trigger, LOW);
}
float HC_SR04::readDistance(){
unsigned long _durration;
float _distance;
delay(50);
digitalWrite(_pin_trigger, LOW);
delayMicroseconds(4);
digitalWrite(_pin_trigger, HIGH);
delayMicroseconds(10);
digitalWrite(_pin_trigger, LOW);
_durration = pulseIn(_pin_echo, HIGH);
_distance = _durration / 29.1 / 2;
_distance = (float)((int)(_distance*10))/10;
return _distance;
}
Thanks