How can I digitalRead a pin that is in pinMode OUTPUT?

后端 未结 11 1088
不知归路
不知归路 2020-12-09 02:30

I have a very simple test sketch in which I\'m trying to set a pin to HIGH and then read its state with digitalRead. Here is my sketch.

<         


        
11条回答
  •  忘掉有多难
    2020-12-09 03:28

    In this case you just want to access the data register itself.

    PORTB and PORTD registers contain the pin data you are looking for. I finally got access to an Arduino to figure it out. You want to use bitRead(PORTD, pin).

    Serial.println(bitRead(PORTD,3)); //Reads bit 3 of register PORTD which contains the current state (high/low) of pin 3.
    

    Reference Bit Read Operation for more information.

提交回复
热议问题