Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

AnalogReference (EXTERNAL) undeclared?

  1. Oct 6, 2012 #1
    Hi! I'm trying to read the voltage( from ARef I assume) by using analogRead.
    I've set analogReference to EXTERNAL, and I'm doing this in main.
    Yet, I'm told that EXERNAL is undeclared. What am I doing wrong?

    #define CPU_PRESCALE(n)(CLKPR=0x80,CLKPR=(n))
    #define CPU_16MHz 0x00

    int main(void)

    // Initialize DDR
    DDRC = 0x0e; // Output (Lamp Status) (Sets output to 3 pins)
    DDRD = 0x00; // Input (Switch Status)

    // Initialize PORT
    PORTD = 0xff;
    int analogInput = 0;
    int analogAmount = ;

    void setup()
    analogReference(EXTERNAL); // use AREF for reference voltage


    analogAmount = analogRead(analogInput);

    //--------------------- D4 ---------------------
    if (!(PIND & 0x10))
    PORTC = 0x0e;
    PORTC = 0x00;
    //--------------------- D5 ---------------------
    if (!(PIND & 0x20))
    PORTC = 0x0e;
    PORTC = 0x00;
  2. jcsd
  3. Oct 8, 2012 #2


    Staff: Mentor

    I wrapped your code in [ code ] [ /code ] tags (without the spaces) so that your indentation is preserved. When you post code, you should do that, too.
    Is EXTERNAL a macro with a value, or are you trying to tell the compiler that analogReference is a function that is defined in an external file.

    It's possible that you are missing the include file that defines EXTERNAL.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook