When I look at the pinout for the tinies, i get confused.
(I found a little about it on the forum: http://arduino.cc/forum/index.php/topic,124139.15.html and it helped in some respect, but also raised me to a higher level of confusion).
Not wanting to redefine the reset-pin, that leaves me with 5 available pins, DIP# 2, 3, 5, 6 and 7.
That looks nice anyway!
Analog in on DIP# 2, 3, and 7
Digital in/out on DIP# 2, 3, 5, 6 and 7
Out with possibility of PWM on DIP# 2, 3, 5 and 6
But how do I call them?
If I write:
digitalRead(4)
I will read the logic value of PIN# 3 ?
And likewise, if I write:
analogRead(2)
I will read the analog value of PIN# 3 ?
In other words: There are several possibilities from the processor connected to a limited number of pins. I can't use them all at the same time, but by telling the processor what I want to do, it will give me that?
I know it is a microcontroller-noobish question, but it has kept me wondering for some time.
It was the possibility of having several different numbers referring to the same pin, but doing different things that had me wondering.("wondering" sounds better than "having an empty look in the eyes and driveling")
I know the arduino has several functions on the same pin, but the number stays the same.
So...
The numbers you use in digitalWrite() are more like the "names" given to the pins.
You can change the names however you want, in the pins_arduino.h and associated files for that "variant."
In this case, it looks like the pins were "named" based on their bit position in the port. "0" is bit 0 of portB,
"1" is bit 1, and so on (there is only portb.) This makes a lot of sense from a technical and implementation point of view. But I always thought that naming the pins after what made sense from a USER point of view was one of the smart things that was done in Arduino; so it might be better if the names matched the pin numbers of the chip instead (so "4" wouldn't work, being the GND pin...)
For the ATtiny85 (8-pin processors) I used "bit numbering" for four reasons...
Historical. Others (e.g. Alessandro Saporetti) before me had used that assignment. I wanted the Tiny Core to be a drop-in replacement for existing cores.
Convenience / sanity. It eliminates the tedious step of translating when referring to the datasheet. PB0 (datasheet reference) is digital pin 0 (Arduino reference). PB1 is digital pin 1. Etcetera.
Uniformity. The m328 mapping forms a U around the processor. The t85 mapping (almost) forms an inverted U around the processor.
Performance. The mapping makes it trivial to implement digital*Fast functions.