You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CM4 with latest OS and WiringPi - clean install of both
Same circuit with python works every-time = so assumed to be correct
Current work-around is to check the size of return and call again if too low
C++ Code
classHCSR04 {
public:HCSR04 (constuint8_t pEchoPin, constuint8_t pTriggerPin) {
this->_EchoPin = pEchoPin;
this->_TriggerPin = pTriggerPin;
pinMode(this->_TriggerPin, OUTPUT);
pinMode(this->_EchoPin, INPUT);
digitalWrite(this->_TriggerPin, LOW);
} // end constructor/* * get the distance reading - RAW * and return it*/uint64_tgetDistance (uint64_t pTimeOut = 50000) {
//// blip the trigger pin// first we set it LOW - so that we are starting from a known state// blip = set HIGH// set LOW to end//digitalWrite(this->_TriggerPin, LOW);
delayMicroseconds(100); // time for GPIO pin to settle ? needed ?// known state now// so blipdigitalWrite(this->_TriggerPin, HIGH);
delayMicroseconds(10); // check whether we can reduce this!!digitalWrite(this->_TriggerPin, LOW);
// wait for echo to return// pTimeOut is unsigned so should never be allowed to approach zerowhile ((digitalRead(this->_EchoPin) == LOW) && (pTimeOut-- > 2)) {
// or fail on timeout
;
}; // end waiting for echo;// record this timethis->_startTimeUsec = micros();
// whilst we have an echowhile ( digitalRead(this->_EchoPin) == HIGH ) {
// wait for the ECHO to finish
;
}; // end of whilst echo echo exists// difference between now and when we first startedreturn (micros() - this->_startTimeUsec);
}
/*****/private:uint8_t _EchoPin;
uint8_t _TriggerPin;
uint64_t _startTimeUsec;
}; // end of class HCSR04
The text was updated successfully, but these errors were encountered:
CM4 with latest OS and WiringPi - clean install of both
Same circuit with python works every-time = so assumed to be correct
Current work-around is to check the size of return and call again if too low
C++ Code
The text was updated successfully, but these errors were encountered: