map()

C 에디터 명령어 ›› Math ››
Parent Previous Next

숫자를 기존 범위에서 새로운 범위로 매핑한다.


사용방법

map(value, fromLow, fromHigh, toLow, toHigh)


value : 매핑할 숫자

fromLow : 현재 범위의 lower bound

fromHigh : 현재 범위의 upper bound

toLow : 새로운 범위의 lower bound

toHigh : 새로운 범위의 upper bound


리턴값

새로 매핑된 값


예제 코드

/* 아날로그 값(10bit)를 8bit로 매핑*/

void setup() {}


void loop()

{

  int val = analogRead(0);

  val = map(val, 0, 1023, 0, 255);

  analogWrite(9, val);

}


Created with the Personal Edition of HelpNDoc: Free EPub and documentation generator