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()
-
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");}
} -
Hi @JCPStevens
What is physically connected to the pins 4 and 6?
Br
Karl@JCPStevens said in DigitalRead():
left=digitalRead(4);
right=digitalRead(6); -
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");} }