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:与 Arduino map()函数类似的值范围转换

Guru**** 2188815 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/682819/msp430g2553-value-tange-conversion-like-arduino-map-function

器件型号:MSP430G2553

您好!

我正在使用 tcs3200颜色传感器,我正在读取2个散射值(最高和最低)。

我想像 Arduino map()函数一样在0-255之间转换此2值,但值不在0-255之间。

示例  

MAP (SensorValue、30、70、0、255)

这是我使用的代码。

int 映射(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;
} 
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好!

    您能更具体地谈谈您的问题吗? 如果我理解正确、返回值不在0-255之间、对吧? 是更大还是更小?
    您的 SensorValue 的范围是多少?
    查看并确保 SensorValue 处于正确范围内、传感器读数正确传导。
    请与我分享此信息、以便我们进一步解决您的问题。

    谢谢、此致、
    Britta
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    考虑溢出。
    2.限制输出,以防输入超出范围。