-
function map(value, min, max, newMin, newMax) { return (value - min) * (newMax - newMin) / (max - min) + newMin; }
value의 현재 범위가 min~max일때
새로운 범위인 newMin~newMax에 맞게 변환합니다.
value가 20이고 범위가 0~100이며
0~360으로 확장하고 싶을때
a = map(20, 0, 100, 0, 360);
a는 72가 되고 이는 20 / 100 * 360과 같습니다.
a = map(20, 0, 100, 100, 0);
이렇게 범위를 뒤집어 80이 나오게 할 수 있고
음수도 문제 없이 잘 됩니다.
아두이노의 map함수
https://www.arduino.cc/reference/en/language/functions/math/map/
Arduino Reference
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. Does not constrain values to within the range, because out-of-range v
www.arduino.cc
댓글