Good Evening together,
I am currently trying to read my Ultrasonic sensor with an "attachIntterupt" function. But somehow it seems to just count the time, instead of telling me the durration of my interrupt. Any suggestions anyone?
I am kind of new to the arduino, so it would be great if someone could explain in "easy words" what was wrong
Here the code:
volatile long unsigned time;
volatile long unsigned Echo=2;
volatile long unsigned Trigger=36;
boolean flag;
void pinChange ()
{
 time = micros();
 flag = true;
}
void setup ()
{
 Serial.begin(9600);
 pinMode(Trigger, OUTPUT);
 pinMode(Echo, INPUT);
 digitalWrite(Echo, HIGH);
 attachInterrupt(0,pinChange,HIGH);
Â
}
void loop()
{
 digitalWrite(Trigger, LOW);
 delayMicroseconds(2);
 digitalWrite(Trigger, HIGH);
 delayMicroseconds(10);
Â
 if (flag)
 {
 Serial.print(time);
 Serial.print("\n");Â
 flag = false;
 time = 0;
 delay(100);
 }
}
And here the output:
540
1004
101772
202112
302552
402996
503440
603892
704344
804804
905244
1005688
1106136
1206628
Looking forward knowing what's wrong
Thanks, notoriou5