Playing with Arduino
A page to record my playing with Arduino
analogReference()

Abstract

The analogReferece() sets the reference voltage for analog input. It just sets a global variable.

Source Code

The analogReference() is defined in hardware/arduino/avr/cores/arduino/wiring_analog.c as below.

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;
}

The input is mode and its type is uint8_t. The mode can be one of ‘DEFAULT’, ‘INTERNAL’ or ‘EXTERNAL’.

This function stores the mode into the global variable named analog_reference. The analog_reference is used in analogRead().

Version

Arduino 1.8.13

Last Update

June 19, 2020

inserted by FC2 system