Analog input pin as digital output pin

From information I got, analog input pin on Arduino can be used as digital input/output by assigning it as pinMode(A0, INPUT/OUTPUT). And using it, digitalWrite (A0, HIGH/LOW).

But I find that in my project, it doesn't perform as stated.
My project is as follows :
Potensiometer is used to control the speed of blinking LED. And to indicate the current speed, I use RGB LED to monitor the speed/value of pot. Since I only need 1 analog input (for pot) and 4 digital outputs (1 for LED and 3 for RGB led), I thought I use Attiny85.
But when using the analog input pin as digital output of the LEDs, the result is not as I programmed.

Curiously I try to simulate it, using Arduino UNO and the result is the same, RGB led does not display as I programmed.
Changing the RGB Led pins to Arduino UNO digital pins however did solve this problem, but of course I am still cannot use Attiny85 for my project.

Any explanation anyone or suggestion? Very much appreciated.

LIFledRGB.ino (1.26 KB)

The code, so everyone can read it.

/* LEDLif using ATTINY85 */
#define ledPin 7 //10 digital io ok
#define redPin 14
#define grnPin 15
#define bluPin 16 //7 digital io ok
#define potPin A5
int potVal;

void setup() {
//   Serial.begin(9600);
   pinMode(ledPin, OUTPUT);
   pinMode(redPin, OUTPUT);
   pinMode(grnPin, OUTPUT);
   pinMode(bluPin, OUTPUT);
   digitalWrite(redPin, LOW);
   digitalWrite(grnPin, LOW);
   digitalWrite(bluPin, LOW);
}

void setColor (int red, int grn, int blu){
  digitalWrite(redPin, red);
  digitalWrite(grnPin, grn);
  digitalWrite(bluPin, blu);
}

void loop() {
  potVal = analogRead(potPin);
  potVal = map(potVal, 0,1023, 200, 500);
  if (potVal <= 250){
    setColor(1,0,0); //color = red
  }
  if ((potVal > 250) && (potVal <= 300)){
    setColor(1,0,1); //color = magenta
  }
  if ((potVal > 300) && (potVal <=400)) {
    setColor(1,1,0); //color = yellow
  }
  if ((potVal > 400) && (potVal <= 450)) {
    setColor(0,1,0); //color = green
  }
  if (potVal > 450) {
    setColor(0,1,1); //color = cyan
  }
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(potVal);                       // wait for a second
  digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
  delay(potVal);                       // wait for a second
}

it doesn't perform as stated.

What does it do ?

Have you tried printing potVal to make sure that you are getting the expected value ?
How is the pot wired ?

As an aside, I find it much easier to use the A* pin names, as you have done for potPin, rather than the pin numbers that they translate to. Having said that, it should not actually cause a problem unless you have the LEDs connected to the wrong pins. I assume that their anodes are plugged into A0, A1 and A2 and that you have current limiting resistors in place

  delay(potVal);                       // wait for a second

Which is correct, the code or the comment ?

hum... ATTINY85 has no such pins

/* LEDLif using ATTINY85 */
#define ledPin 7 //10 digital io ok
#define redPin 14
#define grnPin 15
#define bluPin 16 //7 digital io ok
#define potPin A5

hum... ATTINY85 has no such pins

He/she did say

Curiously I try to simulate it, using Arduino UNO and the result is the same, RGB led does not display as I programmed.

I assume that the code posted relates to a Uno

UKHeliBob:
I assume that the code posted relates to a Uno

OK.. the comment stated

/* LEDLif using ATTINY85 */

@OP try something like this on your arduino UNO (typed here)

#define ledPin 7

#define redPin A0
#define grnPin A1
#define bluPin A2

#define potPin A5

void setRGBColor (byte red, byte grn, byte blu) {
  digitalWrite(redPin, red);
  digitalWrite(grnPin, grn);
  digitalWrite(bluPin, blu);
}

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(grnPin, OUTPUT);
  pinMode(bluPin, OUTPUT);
  setRGBColor(LOW, LOW, LOW);
}

void loop() {
  int potVal = map(analogRead(potPin), 0, 1023, 200, 500);
  if (potVal <= 250) {
    setRGBColor(HIGH, LOW, LOW); //color = red
  } else if ((potVal > 250) && (potVal <= 300)) {
    setRGBColor(HIGH, LOW, HIGH); //color = magenta
  } else if ((potVal > 300) && (potVal <= 400)) {
    setRGBColor(HIGH, HIGH, LOW); //color = yellow
  } else if ((potVal > 400) && (potVal <= 450)) {
    setRGBColor(LOW, HIGH, LOW); //color = green
  } else if (potVal > 450) {
    setRGBColor(LOW, HIGH, HIGH); //color = cyan
  }
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(potVal);
  digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
  delay(potVal);
}

of course connect the pins correctly

Thks for all the responds.
Yes, the code attached is used when I tried to simulate it in Arduino Uno. Thus the pin number.

The comment is there when I first wrote it to Attiny85.
Sorry for the confusion.

I have checked the electronic connections and nothing is wrong with it.
Yes, I connected the RGB led pins to A0, A1 & A2, thru the limiting resistors.

I used A0, A1 & A2 in the code, and similar effect as using the pin 14, 15 & 16 in the code.

In fact when I reconnected the RGB led pins to Arduino Uno's digital pin (say 5, 6 & 7), and rewrite the code for RGB led pins, it perform correctly. The RGB led shows the correct color when I adjust the pot (thus the potVal is correct).

Perhaps those pins are burnt out?

Try the Blink sketch on pins A0, A1 and A2

Does the LED behave as expected ?

I think I know what went wrong.
The pot I used is not properly solder to the strip board (broken track on the stripboard, due to excessive bending).
Thus making the potVal not showing proper value.

And when I tried in Arduino Uno, analog input A5 is not working (maybe burned out???). I found this out when looking at Serial.println(potVal). Thus changing the pot to A4, works fine.

Thank you all for the effort, I really appreciate it.

glad you found what was wrong!