bitRead( PORTD,22) on a Mega

Hi Al, I am trying to read the High/Low Status of a Arduino Mega, Pin 22 and 48 (both set to OUTPUT).

I thought this would work:

 Serial.print(bitRead( PORTD,22));
 Serial.print(",");
 Serial.print(bitRead( PORTD,48));

But it always gives me a : 0

I have seen people ask this question before, but I think they are all UNO. Does anyone know if this is the same command for a Mega>? Or what I am doing wrong?

thanks

what I am doing wrong?

Not posting all your code.

Mark

PORTD is 8 bits wide. Why on earth are you trying to read bit 48??

If you are trying to do direct port reads, you need to know the correct port and bit. Arduino pin numbers have absolutely no relationship to the PORTx registers of the AVR. The digitalRead() function uses a lookup table to find the correct port and bit for your, that's why it takes so long.

Here is the pin map for the Arudino mega. Find pins 48 and 22 and use their correct bit and PORT.

As an example, Digital Pin 48 is next to the pin labelled "PL1" which means it is PORTL, bit 1. So you would use bitRead(PORTL,1)

The function is called 'digitalRead( 22);'.

The macro bitRead() directly on a port is only for advanced users who know the registers of the avr chips.