pulseIn was not declared in this scope

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

Might sound useless, but try adding a blank line at the top :wink:

This looks like a similar problem to the one I have raised “Particle was not declared in this scope”.

Looks like there may be an include or library issue in the Web IDE.

The is a possible workaround in this thread Particle was not declared in this scope

Are you using a Core or a Photon?

If it is a Core above suggestion migth work - for a Photon I can use pulseIn() as expected in either Latest (0.4.7) or 0.4.7.

hi,

i’m using a photon with the particle dev ide. how can i change over the ide to 0.4.7?

thanks

At the moment I don’t think you can - sorry :confused:
But this seems to be a temporary issue.