Go Down

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

#### AWOL

#15
##### Sep 04, 2011, 07:22 pm
..and then go through all the code and change all the range calculations?

Yes, that's one way of doing it.

#### Muneeb

#16
##### Sep 04, 2011, 07:28 pm
ssssshhhhhhhhhhhhhh,
its an exibition gallerie...
not an annoying one

#### AWOL

#17
##### Sep 04, 2011, 07:29 pm
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

#18
##### Sep 04, 2011, 07:34 pm
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

#19
##### Sep 04, 2011, 08:10 pm
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

#20
##### Sep 04, 2011, 09:37 pm
well, i did it 35 cm (but i could up to 3 meter).
because i have less space in my room

#### AWOL

#21
##### Sep 05, 2011, 09:16 am
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

#22
##### Sep 05, 2011, 06:58 pm
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

#23
##### Sep 05, 2011, 08:56 pm
oooooooooooooo
thanks for the info

#### JO3RI

#24
##### Sep 06, 2011, 12:38 pm
He got the point  XD

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

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