Ping))) SENSOR colour slider

well, i did it 35 cm (but i could up to 3 meter).
because i have less space in my room

Are you just joking, or do you really not see the problem with what you have written?

Relating a measurement to the pin number to which the sensor is attached is a little like relating the size of someone's bank balance to their house number.

Let's see if explaining it this way helps...

In your code, you have something like this:

if ( pingPin ==  microseconds /50 /2 )

Using simple algebra, we can rewrite this as:

 if (microseconds == pingPin * 100)

Now, we know that pingPin equals 7, because you've declared it as a constant and it will not change. So the LED will turn on at exactly 700 microseconds.

Now let's say I decide to use digital pin 12 instead of 7 for my sensor. That shouldn't change the behavior of my project at all, if the code is done correctly. But, if we plug 12 into pingPin, then the LED will turn on at 1200 microseconds. Because time is directly related to distance, that means that by simply changing the pin that I gather the sensor data from, the LED will turn on at more than 50% the distance. That's a problem because changing the pin shouldn't change the behavior of the project.

oooooooooooooo :astonished:
thanks for the info

He got the point XD

I think people stayed very polite and helpful and kept on explaining. Big hurray for all the posters 8)
I thought you all would loose your patience, but you didn't. :smiley:

I'm just posting this because, I found it remarkable.