Limits switches 3 and 4 on Port 7 (pins A1 and A6) ...?


#1

I’m able to read the limit switches 1 and 2 on port 3 perfectly.

In an effort to try to understand on which pins the limit switches 3 and 4 appear to the Arduino I tried to read them from port 7. According to the docs. But I could only ever read one of the limit switches. According to the back of the board they should be on A1 and A6. I was only ever able to read both switches using port 6, which contains A3 and A2.

Port 6 of A3 and A2 both work
Port 7 of A1 and A6 only A1 works
Port 8 of A0 and A7 only A0 works

In the code which follows I changed the A1 and A6 to the combinations shown above.

void setup()
{
    Serial.begin(9600);
    pinMode (A4,INPUT_PULLUP);
    pinMode (A5,INPUT_PULLUP);
    Serial.println("start");
}

int iOldY1 = 0 ;
int iOldY2 = 0 ;

void loop()
{    
    int iNewY1 = digitalRead (A4) ;
    int iNewY2 = digitalRead (A5) ;   

    // Only show when a change happens...
    if ((iNewY1 != iOldY1) || (iNewY2 != iOldY2)) {
        Serial.print ("A4=") ;
        Serial.print (iNewY1) ;
        Serial.print ("  A5=") ;
        Serial.print (iNewY2) ;
        Serial.println("") ;
    }

    iOldY1 = iNewY1 ;
    iOldY2 = iNewY2 ;
}

So either the docs are wrong and limit switches are not on port 7, or only half of port 7 is working, or…?


#2

"According to the ATmega328P datasheet, ADC0 through ADC5 are on port C, which is also a regular digital I/O port. However, ADC6 and ADC7 are orphans that can be addressed directly but aren’t part of a digital I/O port. I have no idea why the MCU was designed that way, but that’s the way it is.

So you should be able to use A6 and A7 as analog inputs, but you can’t use them as digital outputs."


#3

What I’m currently using is shown in the attached images…



#4