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

后端 未结 11 955
不知归路
不知归路 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:14

    Keep your pinMode() selection in the setup() function, and try the digitalWrite() and digitalRead() functions.

    setup() will be executed when controller starts and loop() will be the function which keep executing.

    int pin22 = 22;
    void setup()
    {
      Serial.begin(9600);
      pinMode(pin22,output);
    }
    
    void loop()
    {
      digitalWrite(pin22,HIGH);
      digitalRead(pin22);
      digitalWrite(pin22,LOW);
      digitalRead(pin22);
    }
    

提交回复
热议问题