Analog Input pins used as Digital Outputs

Is it possinle to use Analog pins as digital outputs ?
The reference just says "The analog input pins can be used as digital pins, referred to as A0, A1, etc. "

I've got this configured....

// set the LED pins
#define LED_LINE1 A2 // LINE1 LED (Red)
#define LED_LINE2 A3 // LINE2 LED (Yellow)
#define LED_MP3 A6 // MP3 LED (Green)

boolean ledState = HIGH;
const long blinkrate = 1000;

void setup() {

pinMode(LED_LINE1, OUTPUT);
pinMode(LED_LINE2, OUTPUT);
pinMode(LED_MP3, OUTPUT);

}

void updateLEDs() {
void updateLEDs() {

// code for LED Blinking without delay
if (!muted) ledState = HIGH;
currentMillis = millis();
if (muted) {
if (currentMillis - previousMillis >= blinkrate) {
previousMillis = currentMillis;
ledState = !ledState;
}
}
switch(settings.currentMode) {
case MODE_MP3:
digitalWrite(LED_MP3, ledState);
digitalWrite(LED_LINE1, 0);
digitalWrite(LED_LINE2, 0);
break;
case MODE_LINE1:
digitalWrite(LED_LINE1, ledState);
digitalWrite(LED_LINE2, 0);
digitalWrite(LED_MP3, 0);
break;
case MODE_LINE2:
digitalWrite(LED_LINE2, ledState);
digitalWrite(LED_LINE1, 0);
digitalWrite(LED_MP3, 0);
break;
}
}

updateLEDs() is called in a while loop with 100mS delay in it.

When in "MODE_MP3" I'm only getting 200-300mV on pin A6

If your board's a Uno, the analog pins are A0 to A5, seems like you're thinking A1 to A6 so you might be measuring the pin next door to the one you want?

Sorry, I forgot to say it's a Nano, and I'm definitely measuring volts on pin A6

A6 and A7 are only analog inputs on the Nano.

larryd:
A6 and A7 are only analog inputs on the Nano.

That's interesting. I was just looking at the product page here, and it says:

Analog I/O Pins 8

(Not I/O pins 6 and I pins 2 :wink: )

I suppose it's documented somewhere though?

nano io pins.GIF

nano io pins.GIF

That's 8 analog inputs A0-7.
A0-A5 can be used as: analog input/digital input/digital output.
A6 and A7 are analog inputs only.

.

larryd:
A6 and A7 are only analog inputs on the Nano.

Ahhh !! That'll be why then.

I'm out of digital pins, using a 4x4 keypad (D2 to D9), D10, D11, and D12 are comms to the MP3 Player, A4 and A5 are I2C to another module.

I'm going to use A0 and/or A1 then.

I've found some great pin-out diagrams on this site.

It's pretty easy to use a pcf8574 chip to scan a 4x4 keypad, if you need to free up some pins.

Wondering if this will compile :wink:

...
...
void updateLEDs() {
void updateLEDs() {
...
...