Read the digital pin number

How to read the digital pin number when its ON - HIGH. But not the state?

?

Are you trying to read the state of an input pin or output pin?

Perhaps he wants to know which pins are ON.
Or the state of a particular pin (ON or OFF).

The digital pins are numbered from 0 to 13.

When one of these is ON-HIGH wish to read which is the number of Pin.

I NOT wish to read the state of Pin but knowing the Pin number.

You could try this (untested) to determine which pins are currently HIGH:
Incidentally, "ON" or "HIGH" is the state of the pin. It is necessary to read the state of the pin in order to meet your requirement for printing it out.

void setup() {
  Serial.begin( 9600 ) ;
  for ( int i = 0 ; i <= 13 ; i++ ) {
     pinMode( i, INPUT_PULLUP ) ; // or maybe just INPUT
  }

}

void loop() {

  for ( int i = 0 ; i <= 13 ; i++ ) {
     if ( digitalRead( i ) == HIGH ) {
        Serial.print( "pin is now HIGH: ") ;
        Serial.println( i ) ;
     }
  }
  delay(2000);
}

I was bored :slight_smile:
The "state[]" array holds the state of pins 0-13. Traverse the array to see which pins are high (1) or low (0). Also outputs to serial port

void setup() 
{
    Serial.begin(115200);
  // Set as inputs
    DDRD = 0;
    DDRB = 0;
    // (Optional) enable pullups
    PORTD = 0xFF;
    PORTB = 0x3F;
    // Read inputs
    int inputs = PIND + (PINB & 0x3F)*256;
    int state[13];
    
    // Parse out the high bits
    for (int i = 0; i < 14; i++)
    {
        state[i] = ((inputs & (1 << i)) ==  0) ? 0 : 1;
    }
    
    // Display
    for (int j = 0; j < 14; j++)
    {
        if (state[j] == 1)
        {
            Serial.println(j);
        }
    }
}

void loop() {
  // put your main code here, to run repeatedly:

}