Go Down

Topic: Problem getting state and toggling output pin on Arduino Due (Read 1 time) previous topic - next topic

Euhenio

Feb 27, 2013, 02:21 am Last Edit: Feb 27, 2013, 02:34 am by Euhenio Reason: 1
Hi,
I have got a problem with toggling and getting current state of the output pin on Arduino Due and Arduino 1.5.2 software.
The pin stays high all the time and digitalRead(pinnum) always returns 0.
Tried with this code and some variations of it.

Code: [Select]

int pinnum = 13;
void setup() {
 pinMode(pinnum, OUTPUT);  // use on-board LED
}

void loop() {
 digitalWrite(pinnum, !digitalRead(pinnum));
 delay(1000);  // wait around for 1 sec (1000 ms)
}


I would appreciate help very much.

PeterH

I only provide help via the forum - please do not contact me for private consultancy.

Euhenio


What is the problem?


The pin stays high all the time and digitalRead(pinnum) always returns 0. The code I've posted earlier doesn't blink led.
Sorry, forgot to describe the problem in first post. Edited.

Nick Gammon

On the Due, possibly reading an output pin may always return 0. After all, reading from output is not necessarily defined.

I'm moving this to the Due section of the forum.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Euhenio


On the Due, possibly reading an output pin may always return 0. After all, reading from output is not necessarily defined.

I'm moving this to the Due section of the forum.


Is there any work around for this? Or determining current state of output pin is not really possible on Due?

Nick Gammon

Make your own function, that when you do a digitalWrite, it remembers what you set it to.

I personally think, that when you set something as "output" it isn't all that valid to read from it. It's your job to remember what you last wrote.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Euhenio


Make your own function, that when you do a digitalWrite, it remembers what you set it to.

I personally think, that when you set something as "output" it isn't all that valid to read from it. It's your job to remember what you last wrote.


Ok, I got the idea. Thanks for help.

Go Up