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:
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 DIDR0 &= (1 << ADC0D); // enable ADC ADCSRA |= (1 << ADEN); // start conversion ADCSRA |= (1 << ADSC); // loop till done while(ADCSRA & (1 << ADSC)); // use h/l regs unsigned char adcl = ADCL; unsigned char adch = ADCH; int result = (adch << 8) | adcl; // set DIDR0 DIDR0 |= ~(1 << ADC0D); // 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();