2

Author Topic: Can someone explain me about this line of code. Please help  (Read 1189 times)

0 Members and 1 Guest are viewing this topic.

Offline amadordTopic starter

  • Jr. Member
  • **
  • Posts: 21
  • Helpful? 0
Can someone explain me about this line of code. Please help
« 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?

Offline dellagd

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can someone explain me about this line of code. Please help
« Reply #1 on: March 22, 2010, 04:09:11 PM »
um, a little more info plz. Can u plz post the code here?
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,937
  • Helpful? 98
Re: Can someone explain me about this line of code. Please help
« Reply #2 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.

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can someone explain me about this line of code. Please help
« Reply #3 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.

Offline billhowl

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 32
  • Your success is in your hands.
Re: Can someone explain me about this line of code. Please help
« Reply #4 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

Offline Xyver

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: Can someone explain me about this line of code. Please help
« Reply #5 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?

Offline amadordTopic starter

  • Jr. Member
  • **
  • Posts: 21
  • Helpful? 0
Re: Can someone explain me about this line of code. Please help
« Reply #6 on: March 23, 2010, 05:51:27 AM »
okay thanks that explains. thank you very much

 


Get Your Ad Here

data_list