Sony's Developer World forum

    • Home
    • Forum guidelines

    Upcoming maintenance 

     

    Dear Customers and Partners.

    This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.

    This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.

    We apologize for any inconvenience.

     

     

    DigitalRead()

    Spresense
    3
    3
    2637
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      JCPStevens last edited by

      Hello there,

      I wrote this short program with the Arduino IDE. It works with the Arduino, but when I run it on the Spresense the result is that digitalRead() alway high is!
      How do I solve this problem?

      Thanks in advance,
      Marc.

      int left=0;
      int right=0;

      void setup() {
      pinMode(4,INPUT);
      pinMode(6,INPUT);
      Serial.begin(115200);

      }

      void loop() {
      left=digitalRead(4);
      right=digitalRead(6);
      if (left==(HIGH)){
      Serial.println("Left=High");}
      if (left==(LOW)){
      Serial.println("Left=low");}
      if (right==(HIGH)){
      Serial.println("Right=high");}
      if (right==(LOW)){
      Serial.println("Right=low");}
      }

      1 Reply Last reply Reply Quote
      • TE-KarlKomierowski
        TE-KarlKomierowski DeveloperWorld last edited by

        Hi @JCPStevens

        What is physically connected to the pins 4 and 6?

        Br
        Karl

        @JCPStevens said in DigitalRead():

        left=digitalRead(4);
        right=digitalRead(6);

        1 Reply Last reply Reply Quote
        • K
          KamilTomaszewski DeveloperWorld last edited by

          Hi @JCPStevens

          By default, when the mode is set to INPUT, the pin state is HIGH. If you want to change it to LOW, change the pin state to LOW.

          You can use my example below:

          int left=0;
          int right=0;
          
          void setup() {
          pinMode(4,INPUT);
          pinMode(6,INPUT);
          digitalWrite(4, LOW);
          digitalWrite(6, LOW);
          Serial.begin(115200);
          }
          
          void loop() {
          left=digitalRead(4);
          right=digitalRead(6);
          if (left==(HIGH)){
          Serial.println("Left=High");}
          if (left==(LOW)){
          Serial.println("Left=low");}
          if (right==(HIGH)){
          Serial.println("Right=high");}
          if (right==(LOW)){
          Serial.println("Right=low");}
          }
          
          1 Reply Last reply Reply Quote
          • First post
            Last post
          Developer World
          Copyright © 2021 Sony Group Corporation. All rights reserved.
          • Contact us
          • Legal