Go Down

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

AWOL

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

Yes, that's one way of doing it.

Muneeb

ssssshhhhhhhhhhhhhh,
its an exibition gallerie...
not an annoying one

AWOL

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

Muneeb

well,
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

AWOL

Quote
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.

Muneeb

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

AWOL

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.

Arrch

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.

Muneeb

oooooooooooooo  :smiley-eek:
thanks for the info

JO3RI

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.
http://www.JO3RI.be

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

Go Up