analogReadResolution()
설명
analogReadResolution() 은 아두이노 두에, 제로 그리고 MKR 제품군을 위한 아날로그 API의 확장이다.
Sets the size (in bits) of the value returned by analogRead(). It defaults to 10 bits (returns values between 0-1023) for backward compatibility with AVR based boards.
The Due, Zero and MKR Family boards have 12-bit ADC capabilities that can be accessed by changing the resolution to 12. This will return values from analogRead() between 0 and 4095.
문법
analogReadResolution(bits)
매개변수
- bits: determines the resolution (in bits) of the value returned by the analogRead() function. You can set this between 1 and 32. You can set resolutions higher than 12 but values returned by analogRead() will suffer approximation. See the note below for details.
반환값
- 없음
예제 코드
The code shows how to use ADC with different resolutions.
※ 주의 및 경고:
- If you set the analogReadResolution() value to a value higher than your board's capabilities, the Arduino will only report back at its highest resolution, padding the extra bits with zeros. For example: using the Due with analogReadResolution(16) will give you an approximated 16-bit number with the first 12 bits containing the real ADC reading and the last 4 bits padded with zeros.
- If you set the analogReadResolution() value to a value lower than your board's capabilities, the extra least significant bits read from the ADC will be discarded.
- Using a 16 bit resolution (or any resolution higher than actual hardware capabilities) allows you to write sketches that automatically handle devices with a higher resolution ADC when these become available on future boards without changing a line of code.
더보기
- 언어 : analogRead()
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |