# Can I use the ATtiny84 ADC0 pin as both input and output?

I am using the ADC0 (PA0) pin of an Attiny84 to read analog values from an audio circuit. This part is working fine. Since I need to connect the Attiny84 to 8 LEDs, I'd like to use the ADC0 pin as an output also.

Here is the schematic:

simulate this circuit – Schematic created using CircuitLab

But this doesn't work. The LEDs don't light up. (They are turned on based on ADC0 values read in.)

Does this have something to do with enabling pull-ups?

Or is it not possible to switch ADC0 between input and output?

Here is the code:

// set pin as input
DDRA &= ~(1 << PA0);

// unset DIDR0

// start conversion
// loop till done

// use h/l regs

// set DIDR0

// set pin as output
DDRA |= (1 << PA0);

// switch LED on
PORTA |= (1 << PA0);

// switch other LEDs on which have been set as output
//...
PORTA |= (1 << PA1);


The above code is being called from the 8-bit timer overflow interrupt handler. The timer is setup from main() as follows:

// set 8-bit timer
cli();

// set prescaler to 256
TCCR0B |= (1 << CS02);
// set overflow interrupt enable
TIMSK0 |= (1 << TOIE0);

sei();

• Can you add a schematic of what you connected to the ADC0 pin. It sounds like you have connected two things to it (ADC input, LED output). This might be the problem. – Tom L. May 28 '14 at 5:22
• I've added the schematic, Tom. Yes, I've connected the LED. But how else would I use the pin as input and output? – M-V May 28 '14 at 6:25
• I can see that connecting the LM358 output directly to the LED is problematic. But that doesn't explain why the uC output to LEDs on other pins also stop working. Thanks – M-V May 28 '14 at 6:41
• I know this is kind of old, but take a look at my question and the associated answer, as I am successfully using a pin as an output to drive LEDs and an input using the ADC. electronics.stackexchange.com/questions/66431/… – Kurt E. Clothier May 12 '15 at 4:59