Orangutan library PulseIn problem: storing,start(),stop()

ok. checking if I understand this correctly. So if I add the 1000ms delay allows the library time to start storing the info in lastHighPulseInMicroseconds?

No. It takes the library very little time to store or start storing information. The point is that you need to wait until AFTER the pulse has happened because the libary cannot measure a pulse that has not happened yet. The OrangutanPulseIn functions only tell you information about what happened in the past; they do not wait and they cannot predict the future.

–David

Thank you David

I think i got it to work.

#include <avr/io.h>
#include <pololu/orangutan>
#include <pololu/orangutan.h>
#include <pololu/OrangutanDigital/OrangutanDigital.h>
#include <pololu/OrangutanPulseIn/OrangutanPulseIn.h>
#include <avr/interrupt.h>
const unsigned char pin2=IO_C3;

long LastHighPulseMicroseconds=0;


int main(){
		
		while(1){
			OrangutanDigital::setOutput(pin2,LOW);
			OrangutanTime::delayMicroseconds(2);
			OrangutanDigital::setOutput(pin2,HIGH);
			OrangutanTime::delayMicroseconds(5);
			OrangutanDigital::setOutput(pin2,LOW);
			OrangutanPulseIn::start((unsigned char[]){pin2},1);
			OrangutanDigital::setInput(pin2,HIGH_IMPEDANCE);
			delay_ms(1000);
			LastHighPulseMicroseconds=OrangutanPulseIn::toMicroseconds(OrangutanPulseIn::getLastHighPulse(0));
			
			delay_ms(100);
			OrangutanPulseIn::stop();
		}			
	}				

Here is the class that I’m made after i got the ping sensor to work. if any one going to copy the code below; make sure that the header match the header in your AVR studio.
this is for header file in AVR.

#include <pololu/orangutan>
#include <pololu/OrangutanDigital/OrangutanDigital.h>
#include <pololu/OrangutanMotors/OrangutanMotors.h>
#include <avr/io.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <pololu/OrangutanTime/OrangutanTime.h>

	long inches;
	int motorspeed;

class Ping{
	
	
	
	
	
	public:
	long LastHighPulseMicroseconds;
	
	 Ping(){ // !!!!
		 inches=0;
		 LastHighPulseMicroseconds=0;
		 
	 }
	
	
	~Ping(){
		
	}
		
		void PingSensor(const unsigned char Ping2){
			
			//LastHighPulseMicroseconds=0;
			OrangutanDigital::setOutput(Ping2,LOW);
			OrangutanTime::delayMicroseconds(2);
			OrangutanDigital::setOutput(Ping2,HIGH);
			OrangutanTime::delayMicroseconds(5);
			OrangutanDigital::setOutput(Ping2,LOW);
			OrangutanPulseIn::start((unsigned char[]){Ping2},1);
			OrangutanDigital::setInput(Ping2,HIGH_IMPEDANCE);
			OrangutanTime::delayMilliseconds(25);
			
			LastHighPulseMicroseconds=OrangutanPulseIn::toMicroseconds(OrangutanPulseIn::getLastHighPulse(0));
			
			if(LastHighPulseMicroseconds>100)
			{
				OrangutanDigital::setOutput(IO_D1,LOW);
				delay(inches);
				OrangutanDigital::setOutput(IO_D1,HIGH);
				delay(inches);
				OrangutanDigital::setOutput(IO_D1,LOW);
			}
			
			
			//OrangutanPulseIn::stop();
			inches=LastHighPulseMicroseconds*.006699;
			delay_ms(100);
		}			
			
		
	};

Have fun