Go Down

Topic: Ping))) SENSOR colour slider (Read 6006 times) previous topic - next topic


..and then go through all the code and change all the range calculations?

Yes, that's one way of doing it.


its an exibition gallerie...
not an annoying one


I'll repeat the question:
Why should a range calculation be dependent upon the number of the pin the range sensor is attached to?


the ping pin is atached to pin 7
so, if ping sensor (ping pin(pin 7)) is equal to (lets say 35 cm), turn led on


so, if ping sensor (ping pin(pin 7)) is equal to (lets say 35 cm), turn led on

Yes, that could be a really sensible approach.

Not sure in which orthogonal universe that would be though.


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:

Code: [Select]
if ( pingPin ==  microseconds /50 /2 )

Using simple algebra, we can rewrite this as:

Code: [Select]
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  :smiley-eek:
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. :D

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

Nederlandstalige sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Go Up