Society of Robots - Robot Forum

Software => Software => Topic started by: amadord on March 22, 2010, 03:25:12 PM

Title: Can someone explain me about this line of code. Please help
Post by: amadord on March 22, 2010, 03:25:12 PM
I have this code inside the photovore program in arduino. I want to learn what it means.

here's the code:
sensor_right = map(sensor_right, 0, 1023, 0, 255);

what does the numbers mean?
Title: Re: Can someone explain me about this line of code. Please help
Post by: dellagd on March 22, 2010, 04:09:11 PM
um, a little more info plz. Can u plz post the code here?
Title: Re: Can someone explain me about this line of code. Please help
Post by: waltr on March 22, 2010, 05:42:38 PM
Can you look or post the code for the function map()? That is where the answer may be.
Title: Re: Can someone explain me about this line of code. Please help
Post by: Razor Concepts on March 22, 2010, 05:54:06 PM
That is a fancy way of converting a number that is originally from 0 to 1024 (typically ADC reading) to a 0 to 255 value. I believe it is Arduino code.
Title: Re: Can someone explain me about this line of code. Please help
Post by: billhowl on March 22, 2010, 05:56:33 PM
Quote
map(value, fromLow, fromHigh, toLow, toHigh)
Description

Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.

http://www.arduino.cc/en/Reference/Map (http://www.arduino.cc/en/Reference/Map)
Title: Re: Can someone explain me about this line of code. Please help
Post by: Xyver on March 22, 2010, 07:36:46 PM
I believe Razor is correct.  Its converting the values from 0-1023 to 0-255.  I assume its for a photovore?
Title: Re: Can someone explain me about this line of code. Please help
Post by: amadord on March 23, 2010, 05:51:27 AM
okay thanks that explains. thank you very much