analogReference()

概要

analogReference()は、アナログ入力を行う際の参照電圧を設定します。

analogReference()のリファレンスはこちらをご覧ください。

ソースコード

analogReference()は、hardware/arduino/avr/cores/arduino/wiring_analog.c に定義されています。以下に全ソースコードを示します。

1
2
3
4
5
6
7
8
9
uint8_t analog_reference = DEFAULT;

void analogReference(uint8_t mode)
{
        // can't actually set the register here because the default setting
        // will connect AVCC and the AREF pin, which would cause a short if
        // there's something connected to AREF.
        analog_reference = mode;
}

入力はmodeで、uint8_t型の変数です。modeとして設定して意味があるのは、Arduino Unoの場合、DEFAULTとINTERNAL、EXTERNALの3種類です。

この関数は入力されたmodeをグローバル変数のanalog_referenceに保存します。

保存したanalog_referenceは、analogRead()を呼び出すときに利用します。

バージョン

Arduino AVR Boards 1.8.6

最終更新日

March 21, 2023

inserted by FC2 system