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.
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
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).
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.