<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Checking status of Output Pins</title>
		<link>http://forums.leaflabs.com/topic.php?id=718</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:18:32 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=718" rel="self" type="application/rss+xml" />

		<item>
			<title>Silntknight on "Checking status of Output Pins"</title>
			<link>http://forums.leaflabs.com/topic.php?id=718#post-4192</link>
			<pubDate>Wed, 06 Apr 2011 20:55:54 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">4192@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Yes, I realized that my original code was incorrect, but it made sense to use &#60;code&#62;if(digitalRead(randomPin))&#60;/code&#62;. You understood correctly.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Checking status of Output Pins"</title>
			<link>http://forums.leaflabs.com/topic.php?id=718#post-4185</link>
			<pubDate>Wed, 06 Apr 2011 16:36:04 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4185@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I think *I* may be getting confused.&#60;br /&#62;
What is it your trying to do?&#60;/p&#62;
&#60;p&#62;Your original code&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#define randomPin 5
#define conditionalPin 6
void setup() {
 pinMode(randomPin, OUTPUT);
 pinMode(conditionalPin, OUTPUT);
}
void loop() {
 if(randomPin == HIGH) {
  digitalWrite(conditionalPin, HIGH);
 }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;could work, and set &#60;code&#62;conditionalPin HIGH&#60;/code&#62; iff (if and only if) &#60;code&#62;randomPin&#60;/code&#62; has been set &#60;code&#62;HIGH&#60;/code&#62; (by code which is missing from this example) with this small change:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#define randomPin 5
#define conditionalPin 6
void setup() {
 pinMode(randomPin, OUTPUT);
 pinMode(conditionalPin, OUTPUT);
}
void loop() {
 if(digitalRead(randomPin) == HIGH) {
  digitalWrite(conditionalPin, HIGH);
 }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Is that what you want?&#60;/p&#62;
&#60;p&#62;HIGH is always true, so&#60;br /&#62;
&#60;code&#62;while (digitalRead(randomPin))&#60;/code&#62;&#60;br /&#62;
is the same as&#60;br /&#62;
&#60;code&#62;while (digitalRead(randomPin) == HIGH)&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of the LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "Checking status of Output Pins"</title>
			<link>http://forums.leaflabs.com/topic.php?id=718#post-4181</link>
			<pubDate>Wed, 06 Apr 2011 15:24:34 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">4181@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, I think I am understanding this more (after reading it 3-4 times). I meant that &#60;code&#62;digitalWrite(conditionalPin, digitalRead(randomPin));&#60;/code&#62; wouldn't work because I don't necessarily want them to have the same state. I see what you both are saying about the registers, so &#60;code&#62;digitalRead()&#60;/code&#62; for an OUTPUT pin should give me a significant bit. (I like puns).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Checking status of Output Pins"</title>
			<link>http://forums.leaflabs.com/topic.php?id=718#post-4162</link>
			<pubDate>Tue, 05 Apr 2011 20:24:46 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4162@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Silntknight - I believe snigelen's analysis is correct.&#60;/p&#62;
&#60;p&#62;For your case, where the pins are:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;pinMode(randomPin, OUTPUT);
pinMode(conditionalPin, OUTPUT);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The IDR == ODR, and digitalRead should 'Just Work' (TM)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "Checking status of Output Pins"</title>
			<link>http://forums.leaflabs.com/topic.php?id=718#post-4156</link>
			<pubDate>Tue, 05 Apr 2011 17:33:45 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">4156@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks, I definitely just realized that &#60;code&#62;if(randomPin == HIGH)&#60;/code&#62; wouldn't work. I remembered that #define simply replaces &#34;randomPin&#34; with 5 at compile time. Anyway, 'digitalWrite(conditionalPin, digitalRead(randomPin));` probably won't accomplish what I am trying to do. I might be able to make a workaround, but it would be nice to see if it is possible to read the state of an output pin.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>snigelen on "Checking status of Output Pins"</title>
			<link>http://forums.leaflabs.com/topic.php?id=718#post-4154</link>
			<pubDate>Tue, 05 Apr 2011 16:41:23 +0000</pubDate>
			<dc:creator>snigelen</dc:creator>
			<guid isPermaLink="false">4154@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Interesting question, I've never thought about that.&#60;/p&#62;
&#60;p&#62;First&#60;/p&#62;
&#60;p&#62;  if(randomPin == HIGH)&#60;/p&#62;
&#60;p&#62;will not work, it's about the same as &#34;if (5 == 1)&#34; which always will be false.&#60;/p&#62;
&#60;p&#62;And we're talking about OUTPUT-pins here?&#60;/p&#62;
&#60;p&#62;My short guess is it will probably work with something like&#60;/p&#62;
&#60;p&#62;&#60;code&#62;digitalWrite(conditionalPin, digitalRead(randomPin))&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;My longer spekulation/explanation is this.&#60;/p&#62;
&#60;p&#62;digitalWrite will set a bit in the output data register (ODR) (by writing a bit to bit-reset or bit-set-reset register) and digitalRead will return HIGH if the bit in the input data register (IDR) is set, LOW if it's unset.&#60;/p&#62;
&#60;p&#62;So you want to read the ODR-register, but that's no way to do that without going to lower levels.&#60;/p&#62;
&#60;p&#62;But what happens with IDR for an output pin? The reference says (8.1.8 Output configuration)&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
● A read access to the Input Data Register gets the I/O state in open drain mode&#60;br /&#62;
● A read access to the Output Data register gets the last written value in Push-Pull mode&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I'm not sure how to interpret that exactly. &#60;/p&#62;
&#60;p&#62;I think it's like this&#60;/p&#62;
&#60;p&#62;- If the pin is set to OUTPUT (then it will be set to push-pull mode) or OUTPUT_PUSH_PULL, the IDR and ODR will contain the same information. If that's the case you can use digitalRead() to get the value of the last digitalWrite().&#60;/p&#62;
&#60;p&#62;- If the pin is configured as OUTPUT_OPEN_DRAIN, the relevant bit in the registers will be same if a pin is low. If you set the pin high, ODR will be high but IDR will be high if you have external pullup, low if you have external pulldown or have a random value if it's floating. But if you choose open-drain I guess you have some kind of external pullup. In that case ODR and IDR will have the same value.&#60;/p&#62;
&#60;p&#62;And&#60;/p&#62;
&#60;p&#62;&#60;code&#62;while(digitalRead(randomPin))&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;will work for input pins and, if I'm correct above, for OUTPUT pins too.&#60;/p&#62;
&#60;p&#62;Everything untested. Time to sleep.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "Checking status of Output Pins"</title>
			<link>http://forums.leaflabs.com/topic.php?id=718#post-4153</link>
			<pubDate>Tue, 05 Apr 2011 14:55:12 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">4153@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Should this work:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#define randomPin 5
#define conditionalPin 6
void setup() {
 pinMode(randomPin, OUTPUT);
 pinMode(conditionalPin, OUTPUT);
}
void loop() {
 if(randomPin == HIGH) {
  digitalWrite(conditionalPin, HIGH);
 }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I am trying to set pins either HIGH or LOW depending upon the state of that pin or another pin. I don't think that a digitalRead() would work, so would it work the way I wrote the code?&#60;br /&#62;
Also, if you do a digitalRead() on an input pin, does HIGH count as true for a while loop?&#60;br /&#62;
Ex:&#60;br /&#62;
`while(digitalRead(randomPin)) {&#60;br /&#62;
 //Stuff here&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Thanks!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
