DigitalRead()



  • 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");}
    }


  • DeveloperWorld

    Hi @JCPStevens

    What is physically connected to the pins 4 and 6?

    Br
    Karl

    @JCPStevens said in DigitalRead():

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


  • DeveloperWorld

    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");}
    }