This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553: Value tange conversion like arduino map() function

Part Number: MSP430G2553


Hello,

I am using tcs3200 colour sensor and I am reading 2 diffrent value(highest and lowest) .

I want cconver this 2 value between 0-255 like arduino map() function but values not being between 0-255.

Example 

map(SensorValue,30,70,0,255)

this is the code I used.

int map(int x, int in_min, int in_max, in out_min, in out_max)
{
  return (x - in_min) * (out_max - out_min + 1) / (in_max - in_min + 1) + out_min;
}
  • Hi,

    could you please be a bit more specific about your problem? If I understood you correctly, the return value is not between 0-255, right? Is it bigger or smaller?
    What's the range of your SensorValue?
    Take a look and make sure that your SensorValue is in the right range and that the sensor reading is conducted correctly.
    Please share this information with me so we can further pin down your issue.

    Thanks and best regards,
    Britta
  • 1. Think about overflow.
    2. Bound your output, in case the input is out of range.

**Attention** This is a public forum