<?xml version="1.0" encoding="UTF-8"?><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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Arduino: Fade and pulse a LED with just using a DigitalPort</title>
	<atom:link href="http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/</link>
	<description>Featuring Ruby, Rails, Web development, Arduino, Processing, Nabaztag and more...</description>
	<lastBuildDate>Tue, 15 May 2012 02:35:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: tobi</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-688</link>
		<dc:creator>tobi</dc:creator>
		<pubDate>Thu, 31 Mar 2011 09:03:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-688</guid>
		<description>nice</description>
		<content:encoded><![CDATA[<p>nice</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc de Gier</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-687</link>
		<dc:creator>Marc de Gier</dc:creator>
		<pubDate>Wed, 30 Mar 2011 22:04:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-687</guid>
		<description>This is easier:

int ledPin = 13;   
unsigned int i=0;
boolean rise=true;
int period=1000;

 
void setup()
{
  pinMode(ledPin, OUTPUT);     
}
 
void loop()
{
  if(i == period)
  {
    i=1;
    rise= !rise;
  }
  if(rise == false)
  {
    digitalWrite(13, LOW);
    delayMicroseconds(i);
    digitalWrite(13, HIGH);
    delayMicroseconds(period-i);
    i=i+1;
  }
  
  if(rise == true)
  {
    digitalWrite(13, LOW);
    delayMicroseconds(period-i);
    digitalWrite(13, HIGH);
    delayMicroseconds(i);
    i=i+1;
  }
  
}</description>
		<content:encoded><![CDATA[<p>This is easier:</p>
<p>int ledPin = 13;<br />
unsigned int i=0;<br />
boolean rise=true;<br />
int period=1000;</p>
<p>void setup()<br />
{<br />
  pinMode(ledPin, OUTPUT);<br />
}</p>
<p>void loop()<br />
{<br />
  if(i == period)<br />
  {<br />
    i=1;<br />
    rise= !rise;<br />
  }<br />
  if(rise == false)<br />
  {<br />
    digitalWrite(13, LOW);<br />
    delayMicroseconds(i);<br />
    digitalWrite(13, HIGH);<br />
    delayMicroseconds(period-i);<br />
    i=i+1;<br />
  }</p>
<p>  if(rise == true)<br />
  {<br />
    digitalWrite(13, LOW);<br />
    delayMicroseconds(period-i);<br />
    digitalWrite(13, HIGH);<br />
    delayMicroseconds(i);<br />
    i=i+1;<br />
  }</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andri</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-600</link>
		<dc:creator>Andri</dc:creator>
		<pubDate>Fri, 10 Dec 2010 14:47:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-600</guid>
		<description>No problem Tobi...I&#039;ve found another code and with a little bit &quot;patiece&quot;...it works :D
I post the code that I&#039;ve modified...have a nice day!! Thanks!


void setup()  
{ 
  pinMode(9, OUTPUT);
} 

void fade(int pin, int start, int finish, int milliseconds)
{
  uint32_t startMillis = millis();  // remember when we started
  while (true)  // we will &#039;break&#039; when we are done
  {
    uint32_t elapsedTime = millis() - startMillis;  // track the time
    
    // convert the elapsed time into a brightness range
    int brightness = map(elapsedTime, 0, milliseconds, start, finish);
    analogWrite(pin, brightness);
    
    // exit when milliseconds have elapsed
    if (elapsedTime &gt;= milliseconds)
    {
      break;
    }
    delay(1);
  }
}

void loop()  
{ 
fade(9, 0, 255, 1000);  // fade led on pin 9 from min to max over one second
delay(2000);  // hold for 2 seconds
fade(9, 255, 0, 2000);  // fade pin 9 from max to min over 2 seconds
delay(1000);  // hold for 1 second
}</description>
		<content:encoded><![CDATA[<p>No problem Tobi&#8230;I&#8217;ve found another code and with a little bit &#8220;patiece&#8221;&#8230;it works <img src='http://www.rngtng.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
I post the code that I&#8217;ve modified&#8230;have a nice day!! Thanks!</p>
<p>void setup()<br />
{<br />
  pinMode(9, OUTPUT);<br />
} </p>
<p>void fade(int pin, int start, int finish, int milliseconds)<br />
{<br />
  uint32_t startMillis = millis();  // remember when we started<br />
  while (true)  // we will &#8216;break&#8217; when we are done<br />
  {<br />
    uint32_t elapsedTime = millis() &#8211; startMillis;  // track the time</p>
<p>    // convert the elapsed time into a brightness range<br />
    int brightness = map(elapsedTime, 0, milliseconds, start, finish);<br />
    analogWrite(pin, brightness);</p>
<p>    // exit when milliseconds have elapsed<br />
    if (elapsedTime &gt;= milliseconds)<br />
    {<br />
      break;<br />
    }<br />
    delay(1);<br />
  }<br />
}</p>
<p>void loop()<br />
{<br />
fade(9, 0, 255, 1000);  // fade led on pin 9 from min to max over one second<br />
delay(2000);  // hold for 2 seconds<br />
fade(9, 255, 0, 2000);  // fade pin 9 from max to min over 2 seconds<br />
delay(1000);  // hold for 1 second<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tobi</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-599</link>
		<dc:creator>tobi</dc:creator>
		<pubDate>Fri, 10 Dec 2010 09:52:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-599</guid>
		<description>sorry no updated code and not quite sure about the math formula, neither its name :-) it was just a quick hack to get prepared controlling the 8x8 LED Matrix... happy u like it :-)</description>
		<content:encoded><![CDATA[<p>sorry no updated code and not quite sure about the math formula, neither its name <img src='http://www.rngtng.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  it was just a quick hack to get prepared controlling the 8&#215;8 LED Matrix&#8230; happy u like it <img src='http://www.rngtng.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marco</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-598</link>
		<dc:creator>Marco</dc:creator>
		<pubDate>Thu, 09 Dec 2010 18:48:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-598</guid>
		<description>Hi Tobi!
Very nice trick! I am prototyping my thesis project, which involves 24 LEDs fading in and out according to the 24  photoresistors used as on/off switches. I am using n. 3 4051 for the INPUTS and probably I&#039;ll use TLC 5940 for OUTPUTS. Do you think your code it&#039;s suitable for my project? Did you came up with a newer version of the code? That would be awesome and extremely helpful! Please let me know</description>
		<content:encoded><![CDATA[<p>Hi Tobi!<br />
Very nice trick! I am prototyping my thesis project, which involves 24 LEDs fading in and out according to the 24  photoresistors used as on/off switches. I am using n. 3 4051 for the INPUTS and probably I&#8217;ll use TLC 5940 for OUTPUTS. Do you think your code it&#8217;s suitable for my project? Did you came up with a newer version of the code? That would be awesome and extremely helpful! Please let me know</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andri</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-597</link>
		<dc:creator>Andri</dc:creator>
		<pubDate>Thu, 09 Dec 2010 11:05:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-597</guid>
		<description>Hi tobi,

very nice code!! Fabulous...
but I have a question...which mathematical formula  &quot;pt = period * high / (low + high )&quot; is??
Has it a name? Or do you know where I can find it?
I want to work with it to get one cycle of fading-in led...then a piezo works...and finally one cycle of fading-out led...WHITOUT DELAY :D</description>
		<content:encoded><![CDATA[<p>Hi tobi,</p>
<p>very nice code!! Fabulous&#8230;<br />
but I have a question&#8230;which mathematical formula  &#8220;pt = period * high / (low + high )&#8221; is??<br />
Has it a name? Or do you know where I can find it?<br />
I want to work with it to get one cycle of fading-in led&#8230;then a piezo works&#8230;and finally one cycle of fading-out led&#8230;WHITOUT DELAY <img src='http://www.rngtng.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MetaCipher</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-542</link>
		<dc:creator>MetaCipher</dc:creator>
		<pubDate>Sat, 24 Jul 2010 15:02:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-542</guid>
		<description>Comment system totally butchered my code. Is using htmlspecialchars really that hard? Replace ~ with less than sign.

int data = 2;
int clock = 3;
int latch = 4;

boolean Pins[8];

int Count = 0;

int Brightness = 0;
int BrightnessInc = 1;

void setup() {
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
}

void loop() {
  digitalWrite(latch, 0);
  digitalWrite(clock, 0);  
  digitalWrite(data, 0);
  
  for(int i = 0;i ~ 8;i++) {
      if(Count ~ Brightness) {
        Pins[i] = 1;
      }else{
        Pins[i] = 0;
      }
  }  
  
  Count++;
  
  if(Count &gt;= 50) { 
    Count = 0;
    Brightness += BrightnessInc;    
  }
  
  if(Brightness &gt; 50) {
    BrightnessInc = -1;
  }else
  if(Brightness ~ 0) {
    BrightnessInc = 1;
  }
  
  for(int i = 0;i ~ 8;i++) {
    digitalWrite(clock, 0);
    
    digitalWrite(data, Pins[i]);
    
    digitalWrite(clock, 1);
    digitalWrite(data, 0);
  }
 
  digitalWrite(clock, 0); 
  digitalWrite(latch, 1);
}</description>
		<content:encoded><![CDATA[<p>Comment system totally butchered my code. Is using htmlspecialchars really that hard? Replace ~ with less than sign.</p>
<p>int data = 2;<br />
int clock = 3;<br />
int latch = 4;</p>
<p>boolean Pins[8];</p>
<p>int Count = 0;</p>
<p>int Brightness = 0;<br />
int BrightnessInc = 1;</p>
<p>void setup() {<br />
  pinMode(data, OUTPUT);<br />
  pinMode(clock, OUTPUT);<br />
  pinMode(latch, OUTPUT);<br />
}</p>
<p>void loop() {<br />
  digitalWrite(latch, 0);<br />
  digitalWrite(clock, 0);<br />
  digitalWrite(data, 0);</p>
<p>  for(int i = 0;i ~ 8;i++) {<br />
      if(Count ~ Brightness) {<br />
        Pins[i] = 1;<br />
      }else{<br />
        Pins[i] = 0;<br />
      }<br />
  }  </p>
<p>  Count++;</p>
<p>  if(Count &gt;= 50) {<br />
    Count = 0;<br />
    Brightness += BrightnessInc;<br />
  }</p>
<p>  if(Brightness &gt; 50) {<br />
    BrightnessInc = -1;<br />
  }else<br />
  if(Brightness ~ 0) {<br />
    BrightnessInc = 1;<br />
  }</p>
<p>  for(int i = 0;i ~ 8;i++) {<br />
    digitalWrite(clock, 0);</p>
<p>    digitalWrite(data, Pins[i]);</p>
<p>    digitalWrite(clock, 1);<br />
    digitalWrite(data, 0);<br />
  }</p>
<p>  digitalWrite(clock, 0);<br />
  digitalWrite(latch, 1);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MetaCipher</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-541</link>
		<dc:creator>MetaCipher</dc:creator>
		<pubDate>Sat, 24 Jul 2010 15:00:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-541</guid>
		<description>Simple example, using a shift register - makes all 8 LEDs pulsate together (from complete brightness, to nothing):

int data = 2;
int clock = 3;
int latch = 4;

boolean Pins[8];

int Count = 0;

int Brightness = 0;
int BrightnessInc = 1;

void setup() {
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
}

void loop() {
  digitalWrite(latch, 0);
  digitalWrite(clock, 0);  
  digitalWrite(data, 0);
  
  for(int i = 0;i &lt; 8;i++) {
      if(Count = 50) { 
    Count = 0;
    Brightness += BrightnessInc;    
  }
  
  if(Brightness &gt; 50) {
    BrightnessInc = -1;
  }else
  if(Brightness &lt; 0) {
    BrightnessInc = 1;
  }
  
  for(int i = 0;i &lt; 8;i++) {
    digitalWrite(clock, 0);
    
    digitalWrite(data, Pins[i]);
    
    digitalWrite(clock, 1);
    digitalWrite(data, 0);
  }
 
  digitalWrite(clock, 0); 
  digitalWrite(latch, 1);
}</description>
		<content:encoded><![CDATA[<p>Simple example, using a shift register &#8211; makes all 8 LEDs pulsate together (from complete brightness, to nothing):</p>
<p>int data = 2;<br />
int clock = 3;<br />
int latch = 4;</p>
<p>boolean Pins[8];</p>
<p>int Count = 0;</p>
<p>int Brightness = 0;<br />
int BrightnessInc = 1;</p>
<p>void setup() {<br />
  pinMode(data, OUTPUT);<br />
  pinMode(clock, OUTPUT);<br />
  pinMode(latch, OUTPUT);<br />
}</p>
<p>void loop() {<br />
  digitalWrite(latch, 0);<br />
  digitalWrite(clock, 0);<br />
  digitalWrite(data, 0);</p>
<p>  for(int i = 0;i &lt; 8;i++) {<br />
      if(Count = 50) {<br />
    Count = 0;<br />
    Brightness += BrightnessInc;<br />
  }</p>
<p>  if(Brightness &gt; 50) {<br />
    BrightnessInc = -1;<br />
  }else<br />
  if(Brightness &lt; 0) {<br />
    BrightnessInc = 1;<br />
  }</p>
<p>  for(int i = 0;i &lt; 8;i++) {<br />
    digitalWrite(clock, 0);</p>
<p>    digitalWrite(data, Pins[i]);</p>
<p>    digitalWrite(clock, 1);<br />
    digitalWrite(data, 0);<br />
  }</p>
<p>  digitalWrite(clock, 0);<br />
  digitalWrite(latch, 1);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrewcaveman</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-472</link>
		<dc:creator>andrewcaveman</dc:creator>
		<pubDate>Wed, 10 Mar 2010 19:25:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-472</guid>
		<description>Excellent solution for the digital write. I&#039;ve been trying to find a good solution for button input to LED lights using the analogwrite, but the delay function would always null my button input until the loop was complete. This works very well. 
Thanks for giving me new ideas.</description>
		<content:encoded><![CDATA[<p>Excellent solution for the digital write. I&#8217;ve been trying to find a good solution for button input to LED lights using the analogwrite, but the delay function would always null my button input until the loop was complete. This works very well.<br />
Thanks for giving me new ideas.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jason</title>
		<link>http://www.rngtng.com/2009/05/17/arduino-fade-and-pulse-a-led-with-just-using-a-digitalport/comment-page-1/#comment-461</link>
		<dc:creator>jason</dc:creator>
		<pubDate>Fri, 12 Feb 2010 09:35:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.rngtng.com/?p=90#comment-461</guid>
		<description>What about having one LED fade into another?  For example, a red LED fading into a blue LED?</description>
		<content:encoded><![CDATA[<p>What about having one LED fade into another?  For example, a red LED fading into a blue LED?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

