Pin definitions Midiboy

I have taken a look at the schematics and pins_arduino.h (blokas variant)

I’m confused. For example, using the tone command works on pin 13, looking at the schematics
i would have expected may be 14, (or 13 if programmatic pins are zero based).

I can’t seem to find what definition in pins_arduino.h would yield the ‘13’.

(I have also looked at the ArduboyTones code and tried the definitions in there.
Not having a screen makes it a bit hard to just test everything.)

Could someone give me a pointer?

The pin numbers in Arduino are purely logical and don’t tie to the silicon directly. On the MCU, the SPK_A and SPK_B pins are PB0 and PB1, controlled using PORTB, PINB, DDRB I/O registers of the chip.

The magic to map the logical numbers 12 and 13 to the appropriate I/O registers happens in these macros here:

Blokas-Boards/pins_arduino.h at master · BlokasLabs/Blokas-Boards · GitHub

The digitalWrite and other Arduino functions make use of the macros to convert the logical pin number to the hardware registers. This is their abstraction layer for different variants of hardware.

Btw, you can read all about the I/O registers in the ATmega328 datasheet.

1 Like