I want to use 16 pins of ATMega328 (without Arduino board) as Ouptut. I can use 13 digital but how to use Analog Pins as Digital Output?
I have supplied 5V to AVcc and ARef pins and coded as:
AnalogWrite (4, 255); // A4 as digital Out
AnalogWrite(5, 255); // A5 as digital Out
I burned the Arduino Nano Bootloader in the Atmega328 but the above code isnt making A4 and A5 high ... digital meter shows less than 1V on these pins ...
These pins need to drive a Relay via transistor ...
Analog inputs are alternate functions of digital port C pins.
Analog output is a pwm and hence can be used only on timer legs (OCx). Unless software simulated.
Did you remember to set the pinMode as "OUTPUT" in "setup()"?
i.e
pinMode (A4, OUTPUT);
pinMode (A5, OUTPUT);
You can "analogWrite" to any digital pin, whether or not it is PWM-capable, but if the pin is not PWM-capable it will only set the pin HIGH if the PWM value written is >= 128, LOW otherwise.