How to find the hexadecimal number for other pins

I am using this code in order to count PMW width with interrups on a Mega.

However I would like to use interrupts Interupt 2- Pin21 and
Interupt 3- Pin20.

I dont know how to define them since I got no hex address for them.

Please help,

thanks

_4Interupts_Stephane.ino (2.05 KB)

Why can't you do a digitalRead of the pins instead of addressing them with macros?

Hello,
the Pins can Change depending on which Uno it is. Mega 2560 for example is different than a 328. Which Arduino are you using.

Those are, by the way, not hexadecimal numbers but binary numbers.

I'm not sure what 'hex address" you mean. Any number can be written in hex.

Perhaps you want to use digitalPinToInterrupt(pin)? See here.

JA BA, and others, thanks for the replies.

I am using an arduino mega.

I am not using digital read because this method is supposely more accurate for measuring RC Signals.
So yes, I would like to find out the decimal numbers for pins 20 and 21 on Mega.

I use this Google spreadsheet for UNO and MEGA pins:

Pin 20 is PIND 0x02 (Port D, bit 1)
Pin 21 is PIND 0x01 (Port D, bit 0)

I would like to find out the decimal numbers for pins 20 and 21 on Mega.

I am still not getting it.

Yes John, those addresses worked. Your link to find all addresses does not work. It would be nice to have it for the future.

Thanks a lot, I got what I wanted

mitch

laptophead:
Your link to find all addresses does not work. It would be nice to have it for the future.

Fixed above. Sorry about that.

volatile uint8_t& pin_input_reg = *portInputRegister(digitalPinToPort(pin_no));
uint8_t = pin_mask = digitalPinToBitMask(pin_no));

Substitute pin_no with whatever digital pin number you want to use.

portInputRegister, digitalPinToPort, and digitalPinToBitMask are all functions defined in the Arduino core, and will make your code portable across all the AVR variants.