<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Electronics Hobbyist &#187; video</title>
	<atom:link href="http://www.theelectronicshobbyist.com/blog/tag/video/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.theelectronicshobbyist.com/blog</link>
	<description>A Passion for Curiosity and Play</description>
	<lastBuildDate>Fri, 20 Jan 2012 14:54:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>LED Patterns Using DIP Switch and Arduino</title>
		<link>http://www.theelectronicshobbyist.com/blog/led-patterns-using-dip-switch-and-arduino/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/led-patterns-using-dip-switch-and-arduino/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 06:00:31 +0000</pubDate>
		<dc:creator>Natalia</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[DIP switch]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=533</guid>
		<description><![CDATA[When I posted the “LED Control Using DIP Switch” sketch last year (a simple setup the turned on the LED corresponding to that switch position), I also had a slightly modified version of it in which the DIP switch controlled six different light patterns on the LEDs (scroll right, left, in, out, back and forth [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>When I posted the “<a href="http://www.theelectronicshobbyist.com/blog/2010/09/arduino-led-control-using-dip-switch/">LED Control Using DIP Switch</a>” sketch last year (a simple setup the turned on the <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4215" target="_blank">LED</a> corresponding to that switch position), I also had a slightly modified version of it in which the <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4318" target="_blank">DIP switch</a> controlled six different light patterns on the LEDs (scroll right, left, in, out, back and forth and random). It presented a “cleaned-up” version of the code using <span style="font-family: 'Courier New';">for</span> loops and compared it to the “long-hand” version, showing the trade-off between ease of understanding and conciseness. Except that… I forgot to post it.</p>
<p>Last week someone contacted me asking a question about a similar project he is working on and when I wanted to refer him to this modified sketch I realized it wasn’t on the blog. (Here’s the <a href="http://www.theelectronicshobbyist.com/blog/2010/09/arduino-led-control-using-dip-switch/">original sketch</a> and <a href="http://www.theelectronicshobbyist.com/blog/2010/09/arduino-led-control-using-dip-switch-schematic/">schematic</a> for reference).<span id="more-533"></span></p>
<p>What follows below is the missing blog post (not anymore), a comparison between the more readable sketch (easier for beginners to understand) and the more concise version, in a series of snippets showing the main differences between the two versions of the sketch.</p>
<p>The concise version generates a binary sketch that occupies approximately 25% less memory and is almost half as long in lines of code. The entire source code listings are at the very bottom of this post.</p>
<p><em>Note: the line above each snippet reflects the modification that shortened the sketch.</em></p>
<p>1) not using <span style="font-family: 'Courier New';">#define</span> directives for the LED and switch pins on the <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4447" target="_blank">Arduino</a> in order to use <span style="font-family: 'Courier New';">for</span> loops:</p>
<table border="1">
<tbody>
<tr>
<td>
<pre>    } else {
     // default: off
     digitalWrite(LED1, LOW);
     digitalWrite(LED2, LOW);
     digitalWrite(LED3, LOW);
     digitalWrite(LED4, LOW);
     digitalWrite(LED5, LOW);
     digitalWrite(LED6, LOW);
   }</pre>
</td>
<td>
<pre>    } else {
     // default: off
     for (i = 13; i &gt;= 8; i--) {
       digitalWrite(i, LOW);
     }</pre>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>2) using a state variable array (and consequently a <span style="font-family: 'Courier New';">for</span> loop) as opposed to individual state variables:</p>
<table border="1">
<tbody>
<tr>
<td>
<pre>   s1state = digitalRead(S1);
   s2state = digitalRead(S2);
   s3state = digitalRead(S3);
   s4state = digitalRead(S4);
   s5state = digitalRead(S5);
   s6state = digitalRead(S6);</pre>
</td>
<td>
<pre>   for (i = 0, j = 7; i &lt; 6, j &gt;= 2; i++, j--) {
     state[i] = digitalRead(j);
   }</pre>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>3) <span style="font-family: 'Courier New';">if (x)</span> versus <span style="font-family: 'Courier New';">if (x == 1)</span> (when <span style="font-family: 'Courier New';">x</span> is either <span style="font-family: 'Courier New';">0</span> or <span style="font-family: 'Courier New';">1</span>, then the (<span style="font-family: 'Courier New';">x == 1)</span> expression can be written as simply (<span style="font-family: 'Courier New';">x</span>)):</p>
<table border="1">
<tbody>
<tr>
<td>
<pre>    } else if (s5state == 1) {
     // scroll back and forth</pre>
</td>
<td>
<pre>    } else if (state[4]) {
     // scroll back and forth</pre>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>4) long, repetitive code to randomly turn on or not each LED (for a random duration up to 300 milliseconds) replaced with <span style="font-family: 'Courier New';">for</span> loop:</p>
<table border="1">
<tbody>
<tr>
<td>
<pre>    } else if (s6state == 1) {
     // random
     randomSeed(analogRead(3));
     onoroff = random(0, 2);
     millisecs = random(0, 301);
     digitalWrite(LED1, onoroff);
     delay(millisecs);
     randomSeed(analogRead(3));
     onoroff = random(0, 2);
     millisecs = random(0, 301);
     digitalWrite(LED2, onoroff);
     delay(millisecs);
     randomSeed(analogRead(3));
     onoroff = random(0, 2);
     millisecs = random(0, 301);
     digitalWrite(LED3, onoroff);
     delay(millisecs);
     randomSeed(analogRead(3));
     onoroff = random(0, 2);
     millisecs = random(0, 301);
     digitalWrite(LED4, onoroff);
     delay(millisecs);
     randomSeed(analogRead(3));
     onoroff = random(0, 2);
     millisecs = random(0, 301);
     digitalWrite(LED5, onoroff);
     delay(millisecs);
     randomSeed(analogRead(3));
     onoroff = random(0, 2);
     millisecs = random(0, 301);
     digitalWrite(LED6, onoroff);
     delay(millisecs);
   }</pre>
</td>
<td>
<pre>    } else if (state[5]) {
     // random
     for (i = 13; i &gt;= 8; i--) {
       randomSeed(analogRead(i - 8));
       onoroff = random(0, 2);
       millisecs = random(0, 301);
       digitalWrite(i, onoroff);
       delay(millisecs);
     }
   }</pre>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Here’s the full long version:</p>
<ul>
<li>Binary sketch size: 3654 bytes</li>
<li>Code size was sacrificed in order to improve readability for beginners</li>
<li>Sketch length: 205 lines</li>
</ul>
<div style="width: 500px; height: 500px; overflow: auto; border: #cccccc 1px solid; padding: 5px;">
<pre>  // www.TheElectronicsHobbyist.com/blog
  // Natalia Fargasch Norman
  // LED control via DIP switches

  // <a href="http://www.theelectronicshobbyist.com/blog/goto/uno" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/uno';return true;" onmouseout="self.status=''">Arduino</a> pins used for the LEDs
  #define LED1 13
  #define LED2 12
  #define LED3 11
  #define LED4 10
  #define LED5 9
  #define LED6 8

  // Arduino pins used for the switches
  #define S1 7
  #define S2 6
  #define S3 5
  #define S4 4
  #define S5 3
  #define S6 2

  // State of each switch (0 or 1)
  int s1state;
  int s2state;
  int s3state;
  int s4state;
  int s5state;
  int s6state;

  // Random values for LED state and delay
  long onoroff;
  long millisecs;

  void setup() {
    // pins for LEDs are outputs
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
    pinMode(LED4, OUTPUT);
    pinMode(LED5, OUTPUT);
    pinMode(LED6, OUTPUT);
    // pins for switches are inputs
    pinMode(S1, INPUT);
    pinMode(S2, INPUT);
    pinMode(S3, INPUT);
    pinMode(S4, INPUT);
    pinMode(S5, INPUT);
    pinMode(S6, INPUT);
  }

  void loop() {
    s1state = digitalRead(S1);
    s2state = digitalRead(S2);
    s3state = digitalRead(S3);
    s4state = digitalRead(S4);
    s5state = digitalRead(S5);
    s6state = digitalRead(S6);
    if (s1state == 1) {
      // scroll right
      digitalWrite(LED1, HIGH);
      delay(250);
      digitalWrite(LED1, LOW);
      digitalWrite(LED2, HIGH);
      delay(250);
      digitalWrite(LED2, LOW);
      digitalWrite(LED3, HIGH);
      delay(250);
      digitalWrite(LED3, LOW);
      digitalWrite(LED4, HIGH);
      delay(250);
      digitalWrite(LED4, LOW);
      digitalWrite(LED5, HIGH);
      delay(250);
      digitalWrite(LED5, LOW);
      digitalWrite(LED6, HIGH);
      delay(250);
      digitalWrite(LED6, LOW);
    } else if (s2state == 1) {
      // scroll left
      digitalWrite(LED6, HIGH);
      delay(250);
      digitalWrite(LED6, LOW);
      digitalWrite(LED5, HIGH);
      delay(250);
      digitalWrite(LED5, LOW);
      digitalWrite(LED4, HIGH);
      delay(250);
      digitalWrite(LED4, LOW);
      digitalWrite(LED3, HIGH);
      delay(250);
      digitalWrite(LED3, LOW);
      digitalWrite(LED2, HIGH);
      delay(250);
      digitalWrite(LED2, LOW);
      digitalWrite(LED1, HIGH);
      delay(250);
      digitalWrite(LED1, LOW);
    } else if (s3state == 1) {
      // scroll in
      digitalWrite(LED1, HIGH);
      digitalWrite(LED6, HIGH);
      delay(250);
      digitalWrite(LED1, LOW);
      digitalWrite(LED6, LOW);
      digitalWrite(LED2, HIGH);
      digitalWrite(LED5, HIGH);
      delay(250);
      digitalWrite(LED2, LOW);
      digitalWrite(LED5, LOW);
      digitalWrite(LED3, HIGH);
      digitalWrite(LED4, HIGH);
      delay(250);
      digitalWrite(LED3, LOW);
      digitalWrite(LED4, LOW);
    } else if (s4state == 1) {
      // scroll out
      digitalWrite(LED3, HIGH);
      digitalWrite(LED4, HIGH);
      delay(250);
      digitalWrite(LED3, LOW);
      digitalWrite(LED4, LOW);
      digitalWrite(LED2, HIGH);
      digitalWrite(LED5, HIGH);
      delay(250);
      digitalWrite(LED2, LOW);
      digitalWrite(LED5, LOW);
      digitalWrite(LED1, HIGH);
      digitalWrite(LED6, HIGH);
      delay(250);
      digitalWrite(LED1, LOW);
      digitalWrite(LED6, LOW);
    } else if (s5state == 1) {
      // scroll back and forth
      digitalWrite(LED1, HIGH);
      delay(250);
      digitalWrite(LED1, LOW);
      digitalWrite(LED2, HIGH);
      delay(250);
      digitalWrite(LED2, LOW);
      digitalWrite(LED3, HIGH);
      delay(250);
      digitalWrite(LED3, LOW);
      digitalWrite(LED4, HIGH);
      delay(250);
      digitalWrite(LED4, LOW);
      digitalWrite(LED5, HIGH);
      delay(250);
      digitalWrite(LED5, LOW);
      digitalWrite(LED6, HIGH);
      delay(250);
      digitalWrite(LED6, LOW);
      digitalWrite(LED5, HIGH);
      delay(250);
      digitalWrite(LED5, LOW);
      digitalWrite(LED4, HIGH);
      delay(250);
      digitalWrite(LED4, LOW);
      digitalWrite(LED3, HIGH);
      delay(250);
      digitalWrite(LED3, LOW);
      digitalWrite(LED2, HIGH);
      delay(250);
      digitalWrite(LED2, LOW);
    } else if (s6state == 1) {
      // random
      randomSeed(analogRead(3));
      onoroff = random(0, 2);
      millisecs = random(0, 301);
      digitalWrite(LED1, onoroff);
      delay(millisecs);
      randomSeed(analogRead(3));
      onoroff = random(0, 2);
      millisecs = random(0, 301);
      digitalWrite(LED2, onoroff);
      delay(millisecs);
      randomSeed(analogRead(3));
      onoroff = random(0, 2);
      millisecs = random(0, 301);
      digitalWrite(LED3, onoroff);
      delay(millisecs);
      randomSeed(analogRead(3));
      onoroff = random(0, 2);
      millisecs = random(0, 301);
      digitalWrite(LED4, onoroff);
      delay(millisecs);
      randomSeed(analogRead(3));
      onoroff = random(0, 2);
      millisecs = random(0, 301);
      digitalWrite(LED5, onoroff);
      delay(millisecs);
      randomSeed(analogRead(3));
      onoroff = random(0, 2);
      millisecs = random(0, 301);
      digitalWrite(LED6, onoroff);
      delay(millisecs);
    } else {
      // default: off
      digitalWrite(LED1, LOW);
      digitalWrite(LED2, LOW);
      digitalWrite(LED3, LOW);
      digitalWrite(LED4, LOW);
      digitalWrite(LED5, LOW);
      digitalWrite(LED6, LOW);
    }
  }</pre>
</div>
<p>&nbsp;</p>
<p>And here’s the full &#8220;cleaned-up&#8221; version:</p>
<ul>
<li>Binary sketch size: 2826 bytes</li>
<li>Sketch length: 119 lines</li>
</ul>
<div style="width: 500px; height: 500px; overflow: auto; border: #cccccc 1px solid; padding: 5px;">
<pre>  // www.TheElectronicsHobbyist.com/blog
  // Natalia Fargasch Norman
  // LED control via DIP switches

  // Arduino pins used for the LEDs
  // LED1 13
  // LED2 12
  // LED3 11
  // LED4 10
  // LED5 9
  // LED6 8

  // Arduino pins used for the switches
  // S1 7
  // S2 6
  // S3 5
  // S4 4
  // S5 3
  // S6 2

  // State of each switch (0 or 1)
  int state[6];

  // Random values for LED state and delay
  long onoroff;
  long millisecs;

  // loop counters
  int i, j;

  // delay
  int d = 250;

  void setup() {
    // pins for LEDs are outputs
    // LEDs 1-6 on pins 13-8
    for (i = 13; i &gt;= 8; i--) {
      pinMode(i, OUTPUT);
    }
    // pins for switches are inputs
    // switches 1-6 on pins 7-2
    for (i = 7; i &gt;= 2; i--) {
      pinMode(i, INPUT);
    }
  }

  void loop() {
    for (i = 0, j = 7; i &lt; 6, j &gt;= 2; i++, j--) {
      state[i] = digitalRead(j);
    }

    if (state[0]) {
      // scroll right
      for (i = 13; i &gt;= 8; i--) {
        digitalWrite(i, HIGH);
        delay(d);
        digitalWrite(i, LOW);
      }

    } else if (state[1]) {
      // scroll left
      for (i = 8; i &lt;= 13; i++) {
         digitalWrite(i, HIGH);
         delay(d);
         digitalWrite(i, LOW);
       }

   } else if (state[2]) {
       // scroll in
       // light up LEDs on pins i and 8+(13-i)
       for (i = 13; i &gt;= 11; i--) {
        digitalWrite(i, HIGH);
        digitalWrite(21 - i, HIGH);
        delay(d);
        digitalWrite(i, LOW);
        digitalWrite(21 - i, LOW);
      }

    } else if (state[3]) {
      // scroll out
      // light up LEDs on pins i and 8+(13-i)
      for (i = 11; i &lt;= 13; i++) {
         digitalWrite(i, HIGH);
         digitalWrite(21 - i, HIGH);
         delay(d);
         digitalWrite(i, LOW);
         digitalWrite(21 - i, LOW);
       }

    } else if (state[4]) {
       // scroll back and forth
       for (i = 13; i &gt;= 8; i--) {
        digitalWrite(i, HIGH);
        delay(d);
        digitalWrite(i, LOW);
      }
      for (i = 9; i &lt;= 12; i++) {
        digitalWrite(i, HIGH);
        delay(d);
        digitalWrite(i, LOW);
      }

    } else if (state[5]) {
       // random
       for (i = 13; i &gt;= 8; i--) {
        randomSeed(analogRead(i - 8));
        onoroff = random(0, 2);
        millisecs = random(0, 301);
        digitalWrite(i, onoroff);
        delay(millisecs);
      }      

    } else {
      // default: off
      for (i = 13; i &gt;= 8; i--) {
        digitalWrite(i, LOW);
      }
    }
  }</pre>
</div>
<p>Check out the <a href="http://www.youtube.com/watch?v=fHVdCT-iZwk" target="_blank">video</a> of this sketch in action.</p>
<p>You might also enjoy:<ol>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-led-control-using-dip-switch/' rel='bookmark' title='Arduino LED Control Using DIP Switch | Part 1'>Arduino LED Control Using DIP Switch | Part 1</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-3-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 3'>Controlling a Seven-Segment Display Using Arduino Part 3</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-with-buttons/' rel='bookmark' title='Arduino 2-Digit 7-Segment Display with Buttons | Part 4'>Arduino 2-Digit 7-Segment Display with Buttons | Part 4</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-2-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 2'>Controlling a Seven-Segment Display Using Arduino Part 2</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/led-patterns-using-dip-switch-and-arduino/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LED Bar Graph: Testing the Ardweeny</title>
		<link>http://www.theelectronicshobbyist.com/blog/led-bar-graph-testing-the-ardweeny/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/led-bar-graph-testing-the-ardweeny/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 01:00:25 +0000</pubDate>
		<dc:creator>Natalia</dc:creator>
				<category><![CDATA[Arduino Clone]]></category>
		<category><![CDATA[Kit]]></category>
		<category><![CDATA[Ardweeny]]></category>
		<category><![CDATA[circuit]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[kit]]></category>
		<category><![CDATA[LED bar graph]]></category>
		<category><![CDATA[schematic]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[soldering]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=409</guid>
		<description><![CDATA[A while ago I purchased an Ardweeny kit, but hadn&#8217;t put it together and tested it until now. The Ardweeny is a small, breadboard friendly Arduino clone. In fact, it is the smallest Arduino clone that I know of, and the tiny board is backpacked on top of the ATMega chip. Here are the parts [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>A while ago I purchased an <a href="http://www.theelectronicshobbyist.com/blog/goto/ardweeny">Ardweeny kit</a>, but hadn&#8217;t put it together and tested it until now. The <a href="http://www.theelectronicshobbyist.com/blog/goto/ardweeny" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/ardweeny';return true;" onmouseout="self.status=''">Ardweeny</a> is a small, <a href="http://www.theelectronicshobbyist.com/blog/goto/breadboard" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/breadboard';return true;" onmouseout="self.status=''">breadboard</a> friendly <a href="http://www.theelectronicshobbyist.com/blog/goto/uno" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/uno';return true;" onmouseout="self.status=''">Arduino</a> clone. In fact, it is the smallest Arduino clone that I know of, and the tiny board is backpacked on top of the ATMega chip.<br />
<a href="http://www.theelectronicshobbyist.com/blog/goto/ardweeny" target="_blank"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="size-medium wp-image-410 aligncenter" title="ardweeny" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-300x196.jpg" alt="Ardweeny" width="300" height="196" /></a><br />
Here are the parts laid out before I put the Ardweeny together: PCB, ATMega, headers and 7 parts. <em>Tip: double check that you received the correct parts; I received a 470K Ohm resistor (yellow-violet-yellow) instead of a 470 Ohm (yellow-violet-brown) one.</em><br />
<span id="more-409"></span><a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-parts.jpg"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-medium wp-image-430" title="ardweeny-parts" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-parts-300x200.jpg" alt="Ardweeny parts" width="300" height="200" /></a><br />
The assembly manual that comes with the Ardweeny is illustrated in color, and explains how to put it together in great detail, step-by-step. It is a very easy kit to put together, perfect for a beginner. There isn&#8217;t a lot of soldering involved, either. (There are only 7 parts after all!)<br />
<a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-manual.jpg"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-medium wp-image-431" title="ardweeny-manual" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-manual-300x234.jpg" alt="Ardweeny manual" width="300" height="234" /></a><br />
Here is the final product, assembled and ready to go! Isn&#8217;t it tiny? The <a href="http://www.theelectronicshobbyist.com/blog/goto/ardweeny">Ardweeny</a> comes preloaded with the &#8220;Blink&#8221; sketch. In order to program it you will need an <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4414&amp;affiliate_banner_id=1" target="_blank">FTDI breakout board</a> and <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4191&amp;affiliate_banner_id=1" target="_blank">USB miniB cable</a>. Upon hooking it up for the first time the green LED should blink.<br />
<a href="http://www.theelectronicshobbyist.com/blog/goto/ardweeny" target="_blank"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-medium wp-image-432" title="ardweeny-finished" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-finished-300x261.jpg" alt="Ardweeny" width="300" height="261" /></a><br />
To test it I put together a simple circuit connecting a LED bar graph display and a variable resistor to the Ardweeny. Turning the dial on the trimpot lights the LEDs on the bar graph display accordingly. Here&#8217;s the setup:<br />
<a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-led-bar.jpg"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-medium wp-image-433" title="ardweeny-led-bar" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-led-bar-300x243.jpg" alt="Ardweeny LED bar graph project" width="300" height="243" /></a><br />
Here&#8217;s the schematic showing how the circuit was wired:<br />
<a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-schematic.jpg"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-medium wp-image-435" title="ardweeny-schematic" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/11/ardweeny-schematic-258x300.jpg" alt="Ardweeny LED bar graph schematic" width="258" height="300" /></a><br />
Here&#8217;s a quick <a href="http://www.youtube.com/watch?v=u2ZY6b3FGxg" target="_blank">video</a> of the Ardweeny in action.</p>
<p>And here&#8217;s the sketch:</p>
<pre>// www.TheElectronicsHobbyist.com/blog
// Natalia Fargasch Norman
// Trimpot display using LED bar graph

// loop variables and trimpot reading
int i, j, val;

void setup() {
  for (i = 0; i &lt; 10; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  for (i = 0; i &lt; 10; i++) {
    digitalWrite(i, HIGH);
  }
  // trimpot connected to analog pin 0
  val = analogRead(0);
  // analogRead returns number
  // between 0 and 1023, scaling
  // for the 10 LEDs in the bar graph
  j = val / 100;
  for (i = 0; i &lt; j; i++) {
    // LED bar graph is common anode, LOW is on
    digitalWrite(i, LOW);
  }
}</pre>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/led-bar-graph-testing-the-ardweeny/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Arduino RGB LED Spinning Night Light &#124; Part 1</title>
		<link>http://www.theelectronicshobbyist.com/blog/arduino-rgb-led-spinning-night-light/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/arduino-rgb-led-spinning-night-light/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 05:00:36 +0000</pubDate>
		<dc:creator>Natalia</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[DC motor]]></category>
		<category><![CDATA[RGB LED]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=296</guid>
		<description><![CDATA[This month&#8217;s project uses the Arduino to control a motor and an RGB LED to create an aquarium style spinning night light. The initial idea was to recycle empty toilet paper tubes to serve as the lampshade, but it turns out the project looks much more attractive and colorful using white paper. (I haven&#8217;t given [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/07/arduino-rgb-nightlight.jpg"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="size-full wp-image-297 alignright" title="arduino-rgb-nightlight" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/07/arduino-rgb-nightlight.jpg" alt="Arduino RGB LED Night Light" width="350" height="175" /></a>This month&#8217;s project uses the <a href="http://www.theelectronicshobbyist.com/blog/goto/uno" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/uno';return true;" onmouseout="self.status=''">Arduino</a> to control a <a href="http://www.theelectronicshobbyist.com/blog/goto/motor" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/motor';return true;" onmouseout="self.status=''">motor</a> and an RGB LED to create an aquarium style spinning night light.</p>
<p>The initial idea was to recycle empty toilet paper tubes to serve as the lampshade, but it turns out the project looks much more attractive and colorful using white paper. (I haven&#8217;t given up on the idea of finding a use for the empty tubes, though. Suggestions are welcome.)</p>
<p>A simple <a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_2081895_-1" target="_blank">DC Motor<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a> is used to spin the lamp structure, and a jar lid serves as the base. There is (a lot of) room for improvement in the design of the lamp, but I&#8217;m a computer scientist and wanna-be crafter at best.<br />
<span id="more-296"></span><br />
I intend to revisit these projects in the future, and make them stand alone using smaller Arduino boards and sporting a nicer finish (something worthy of showing guests). For now the purpose of these projects is solely educational (in a microcontroller programming way, not hand crafting).</p>
<p>In the upcoming posts we will explore the assembly of the night light, as well as the circuit and Arduino sketch that make the project work.</p>
<p>Parts list:</p>
<ul>
<li><a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4221&amp;affiliate_banner_id=1" target="_blank">Arduino Duemilanove</a></li>
<li><a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4227&amp;affiliate_banner_id=1" target="_blank">Mini Breadboard</a></li>
<li><a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_2081895_-1" target="_blank">DC Motor<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a></li>
<li><a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4212&amp;affiliate_banner_id=1" target="_blank">RGB LED</a></li>
<li><a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_36311_-1">1N914 Diode<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a></li>
<li><a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_178597_-1">2N3904 Transistor<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a></li>
<li><a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4373&amp;affiliate_banner_id=1" target="_blank">100 Ohm Resistor</a></li>
<li><a href="http://www.amazon.com/gp/product/B001AMWN1Q?ie=UTF8&amp;tag=Squid744799-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B001AMWN1Q">147 Ohm Resistor</a></li>
<li><a href="http://www.amazon.com/gp/product/B0017KDZ4A?ie=UTF8&amp;tag=Squid744799-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B0017KDZ4A">82 Ohm Resistor</a></li>
<li><a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_116572_-1">Soldering iron<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a></li>
<li><a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_170457_-1">Solder<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a></li>
<li><a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_419160_-1">Heat-shrink tubing<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a></li>
<li><a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4242&amp;affiliate_banner_id=1" target="_blank">Jumper Wires</a> of assorted lengths</li>
<li>White paper</li>
<li>Jar lid</li>
<li>Mounting tape</li>
</ul>
<p>I have recorded a short <a href="http://www.youtube.com/watch?v=zaAh-3RbcuY" target="_blank">video of the Arduino RGB LED Spinning Night Light</a> in action.</p>
<p>And here is the Arduino sketch:</p>
<pre>// www.TheElectronicsHobbyist.com/blog
// Natalia Fargasch Norman
// RGB LED night light using Arduino

// Arduino pins used for motor and LEDs
#define MOTOR 3
#define RED 9
#define GREEN 10
#define BLUE 11

// pins for motor and LEDs are outputs
void setup() {
  pinMode(MOTOR, OUTPUT);
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
}

void loop() {
  // set motor speed, between 0 and 255
  analogWrite(MOTOR, 69);

  // fade from aqua to magenta
  for (int i = 0; i < 256; i++) {
    analogWrite(RED, 255-i);
    analogWrite(GREEN, i);
    analogWrite(BLUE, 0);
    delay(50);
  }

  // fade from magenta to aqua
  for (int i = 0; i < 256; i++) {
    analogWrite(RED, i);
    analogWrite(GREEN, 255-i);
    analogWrite(BLUE, 0);
    delay(50);
  }

}</pre>
<p>You might also enjoy:<ol>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-rgb-led-control-spinning-night-light/' rel='bookmark' title='Arduino RGB LED Control for the Spinning Night Light | Part 4'>Arduino RGB LED Control for the Spinning Night Light | Part 4</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-rgb-led-spinning-night-light-assembly/' rel='bookmark' title='Arduino RGB LED Spinning Night Light: Assembly | Part 2'>Arduino RGB LED Spinning Night Light: Assembly | Part 2</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-motor-control-spinning-night-light/' rel='bookmark' title='Arduino Motor Control for the Spinning Night Light | Part 3'>Arduino Motor Control for the Spinning Night Light | Part 3</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-4-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 4'>Controlling a Seven-Segment Display Using Arduino Part 4</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/arduino-rgb-led-spinning-night-light/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Arduino 2-Digit 7-Segment Display with Buttons &#124; Part 4</title>
		<link>http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-with-buttons/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-with-buttons/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 05:00:42 +0000</pubDate>
		<dc:creator>Natalia</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[7-segment display]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=267</guid>
		<description><![CDATA[This week we modify the original circuit and sketch to include two buttons, one to control each digit of the display. Here&#8217;s what the setup looks like: And here&#8217;s the complete sketch: // www.TheElectronicsHobbyist.com/blog // Natalia Fargasch Norman // Dual seven-segment LED Display with buttons // Common Anode digit 1 pin 10 // Common Anode [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>This week we modify the original circuit and sketch to include two buttons, one to control each digit of the display.</p>
<p>Here&#8217;s what the setup looks like:</p>
<p><a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/06/seven-segment-button.jpg"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-medium wp-image-268" title="seven-segment-button" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/06/seven-segment-button-300x216.jpg" alt="2-Digit 7-Segment Display" width="300" height="216" /></a></p>
<p>And here&#8217;s the complete sketch:<br />
<span id="more-267"></span></p>
<pre>// www.TheElectronicsHobbyist.com/blog
// Natalia Fargasch Norman
// Dual seven-segment LED Display with buttons
// Common Anode digit 1 pin 10
// Common Anode digit 2 pin 5

//       CA1 G  F  A  B
//        |  |  |  |  |      -&gt; pins and segments they control
//   ---------    ---------
//   |   A   |    |   A   |
//  F|       |B  F|       |B
//   |---G---|    |---G---|
//  E|       |C  E|       |C
//   |   D   |    |   D   |
//   ---------    ---------
//        |  |  |  |  |      -&gt; pins and segments they control
//        D  DP E  C CA2         

// Segments that make each number when lit:
// 0 =&gt; -FEDCBA
// 1 =&gt; ----BC-
// 2 =&gt; G-ED-BA
// 3 =&gt; G--DCBA
// 4 =&gt; GF--CB-
// 5 =&gt; GF-DC-A
// 6 =&gt; GFEDC-A
// 7 =&gt; ----CBA
// 8 =&gt; GFEDCBA
// 9 =&gt; GF-DCBA

// Arduino digital pins used to light up
// corresponding segments on the LED display
#define A 3
#define B 2
#define C 6
#define D 8
#define E 7
#define F 4
#define G 5

// Pushbuttons connected to pins 9 and 10
#define BTN1 9
#define BTN2 10

// Pins driving common anodes
#define CA1 13
#define CA2 12

// Pins for A B C D E F G, in sequence
const int segs[7] = { A, B, C, D, E, F, G };

// Segments that make each number
const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010,
0b0000010, 0b1111000, 0b0000000, 0b0010000 };

int digit1 = 0;
int digit2 = 0;

void setup() {
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(BTN1, INPUT);
  pinMode(BTN2, INPUT);
  pinMode(CA1, OUTPUT);
  pinMode(CA2, OUTPUT);
}

void loop() {

  // check button1
  int val1 = digitalRead(BTN1);
  if (val1 == HIGH) {
    digit1++;
    digit1 %= 10;
    delay(10);
  }

  // check button2
  int val2 = digitalRead(BTN2);
  if (val2 == HIGH) {
    digit2++;
    digit2 %= 10;
    delay(10);
  }

  // display number
  unsigned long startTime = millis();
  for (unsigned long elapsed=0; elapsed &lt; 600; elapsed = millis() - startTime) {
    lightDigit1(numbers[digit1]);
    delay(5);
    lightDigit2(numbers[digit2]);
    delay(5);
  }
}

void lightDigit1(byte number) {
  digitalWrite(CA1, LOW);
  digitalWrite(CA2, HIGH);
  lightSegments(number);
}

void lightDigit2(byte number) {
  digitalWrite(CA1, HIGH);
  digitalWrite(CA2, LOW);
  lightSegments(number);
}

void lightSegments(byte number) {
  for (int i = 0; i &lt; 7; i++) {
    int bit = bitRead(number, i);
    digitalWrite(segs[i], bit);
  }
}</pre>
<p>Here&#8217;s a video of the <a href="http://www.theelectronicshobbyist.com/blog/goto/uno" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/uno';return true;" onmouseout="self.status=''">Arduino</a> <a href="http://www.youtube.com/watch?v=NgssVuNDYgw" target="_blank">2-digit 7-segment display counter with buttons</a> in action.</p>
<p>You might also enjoy:<ol>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-3-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 3'>Controlling a Seven-Segment Display Using Arduino Part 3</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-counter/' rel='bookmark' title='Arduino 2-Digit 7-Segment Display Counter | Part 1'>Arduino 2-Digit 7-Segment Display Counter | Part 1</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-4-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 4'>Controlling a Seven-Segment Display Using Arduino Part 4</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-with-buttons-sketch/' rel='bookmark' title='Arduino 2-Digit 7-Segment Display with Buttons: Sketch | Part 5'>Arduino 2-Digit 7-Segment Display with Buttons: Sketch | Part 5</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-with-buttons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino 2-Digit 7-Segment Display Counter &#124; Part 1</title>
		<link>http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-counter/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-counter/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 05:00:28 +0000</pubDate>
		<dc:creator>Natalia</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[7-segment display]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[LED]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=185</guid>
		<description><![CDATA[This month&#8217;s Arduino project is to build two 2-digit 7-segment LED display circuits and sketches, one that counts up and one that counts up using mini push buttons. The next posts will explain the circuits and the Arduino sketches. (Here&#8217;s a simpler, 1-digit 7-segment display using Arduino). Materials: Arduino Duemilanove (or Uno) 1 2-digit 7-segment display [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/05/2-digit-display.jpg"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-medium wp-image-186" title="2-digit-display" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/05/2-digit-display-217x300.jpg" alt="2-digit 7-segment display" width="174" height="240" /></a>This month&#8217;s <a href="http://www.theelectronicshobbyist.com/blog/goto/uno" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/uno';return true;" onmouseout="self.status=''">Arduino</a> project is to build two 2-digit 7-segment LED display circuits and sketches, one that counts up and one that counts up using mini push buttons. The next posts will explain the circuits and the Arduino sketches. (Here&#8217;s a simpler, <a href="http://www.theelectronicshobbyist.com/blog/2010/02/controlling-a-seven-segment-display-using-arduino-part-1-of-4/">1-digit 7-segment display using Arduino</a>).</p>
<p>Materials:</p>
<ul>
<li><a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4221&amp;affiliate_banner_id=1" target="_blank">Arduino Duemilanove</a> (or <a href="http://www.theelectronicshobbyist.com/blog/goto/uno">Uno</a>)</li>
<li>1 <a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=https%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_1955781_-1">2-digit 7-segment display<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a> (I got a <a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_18201_-1" target="_blank">50-piece LED display grab bag<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a> for better value; the one I used was configured as shown)</li>
<li>2 <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4211&amp;affiliate_banner_id=1" target="_blank">Mini push button switches</a></li>
<li>9 <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4373&amp;affiliate_banner_id=1" target="_blank">Resistors, 100 Ohm</a></li>
<li>2 <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4383&amp;affiliate_banner_id=1" target="_blank">Resistors, 10K Ohm</a></li>
<li><a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/05/seven-segment-count.jpg"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-medium wp-image-187" title="seven-segment-count" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/05/seven-segment-count-300x225.jpg" alt="2-digit 7-segment display project on breadboard" width="300" height="225" /></a>2 <a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_38375_-1">2N3906 transistors (PNP)<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a></li>
<li>1 <a href="http://www.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProduct_10001_10001_194299_-1">Solderless breadboard<img style="border: none !important; margin: 0px !important;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a></li>
<li><a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4242&amp;affiliate_banner_id=1" target="_blank">Jumper Wires</a> in assorted lengths</li>
</ul>
<p>Sketch for counting up without buttons:<br />
<span id="more-185"></span></p>
<pre>// www.TheElectronicsHobbyist.com/blog
// Natalia Fargasch Norman
// Dual seven-segment LED Display
// Common Anode digit 1 pin 10
// Common Anode digit 2 pin 5

//       CA1 G  F  A  B
//        |  |  |  |  |      -&gt; pins and segments they control
//   ---------    ---------
//   |   A   |    |   A   |
//  F|       |B  F|       |B
//   |---G---|    |---G---|
//  E|       |C  E|       |C
//   |   D   |    |   D   |
//   ---------    ---------
//        |  |  |  |  |      -&gt; pins and segments they control
//        D  DP E  C CA2         

// Segments that make each number when lit:
// 0 =&gt; -FEDCBA
// 1 =&gt; ----BC-
// 2 =&gt; G-ED-BA
// 3 =&gt; G--DCBA
// 4 =&gt; GF--CB-
// 5 =&gt; GF-DC-A
// 6 =&gt; GFEDC-A
// 7 =&gt; ----CBA
// 8 =&gt; GFEDCBA
// 9 =&gt; GF-DCBA

// Arduino digital pins used to light up
// corresponding segments on the LED display
#define A 3
#define B 2
#define C 6
#define D 8
#define E 7
#define F 4
#define G 5

// Pins driving common anodes
#define CA1 13
#define CA2 12

// Pins for A B C D E F G, in sequence
const int segs[7] = { A, B, C, D, E, F, G };

// Segments that make each number
const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010,
0b0000010, 0b1111000, 0b0000000, 0b0010000 };

void setup() {
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(CA1, OUTPUT);
  pinMode(CA2, OUTPUT);
}

void loop() {
  for (int digit1=0; digit1 &lt; 10; digit1++) {
    for (int digit2=0; digit2 &lt; 10; digit2++) {
      unsigned long startTime = millis();
      for (unsigned long elapsed=0; elapsed &lt; 600; elapsed = millis() - startTime) {
        lightDigit1(numbers[digit1]);
        delay(5);
        lightDigit2(numbers[digit2]);
        delay(5);
      }
    }
  }
}

void lightDigit1(byte number) {
  digitalWrite(CA1, LOW);
  digitalWrite(CA2, HIGH);
  lightSegments(number);
}

void lightDigit2(byte number) {
  digitalWrite(CA1, HIGH);
  digitalWrite(CA2, LOW);
  lightSegments(number);
}

void lightSegments(byte number) {
  for (int i = 0; i &lt; 7; i++) {
    int bit = bitRead(number, i);
    digitalWrite(segs[i], bit);
  }
}</pre>
<p>Here&#8217;s a video of the <a href="http://www.youtube.com/watch?v=bEE9ouaXEbU" target="_blank">2-digit 7-segment display counter in action</a>.</p>
<p>You might also enjoy:<ol>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-with-buttons/' rel='bookmark' title='Arduino 2-Digit 7-Segment Display with Buttons | Part 4'>Arduino 2-Digit 7-Segment Display with Buttons | Part 4</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-4-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 4'>Controlling a Seven-Segment Display Using Arduino Part 4</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-counter-sketch/' rel='bookmark' title='Arduino 2-Digit 7-Segment Display Counter: Sketch | Part 3'>Arduino 2-Digit 7-Segment Display Counter: Sketch | Part 3</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-3-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 3'>Controlling a Seven-Segment Display Using Arduino Part 3</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-counter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Controlling a Seven-Segment Display Using Arduino Part 4</title>
		<link>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-4-of-4/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-4-of-4/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 07:00:19 +0000</pubDate>
		<dc:creator>Natalia</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[7-segment display]]></category>
		<category><![CDATA[bits]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[LED]]></category>
		<category><![CDATA[pins]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=21</guid>
		<description><![CDATA[The third and final Arduino sketch uses bits to represent each segment and is a reduced code version of the previous sketch (1,210 bytes for sketch #3 instead of 1,852 bytes for sketch #2). A ten element array holds a byte for each number 0-9 that specifies what segments should be lit (pin low). Bit [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>The third and final <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4221&amp;affiliate_banner_id=1" target="_blank">Arduino</a> sketch uses bits to represent each segment and is a reduced code version of the previous sketch (1,210 bytes for sketch #3 instead of 1,852 bytes for sketch #2). A ten element array holds a byte for each number 0-9 that specifies what segments should be lit (pin low). Bit 0 corresponds to segment A, bit 1 to segment B and so on. In order to display the number 1, segments B and C need to be lit, so that is represented by the value 0b1111001. Function &#8220;lightSegments&#8221; reads these bits in sequence and sets the corresponding segments accordingly.</p>
<p><span id="more-21"></span></p>
<p>Sketch #3:</p>
<pre>
// www.TheElectronicsHobbyist.com/blog
// Natalia Fargasch Norman
// Seven-segment LED Display
// Common Anode pins 3 and 8

//   G F + A B
//   | | | | |   -&gt; pins and segments they control
//   ---------
//  F|   A   |B
//   |---G---|   -&gt; segments
//  E|   D   |C
//   ---------
//   | | | | |   -&gt; pins and segments they control
//   E D + C DP

// Segments that make each number when lit:
// 0 =&gt; -FEDCBA
// 1 =&gt; ----BC-
// 2 =&gt; G-ED-BA
// 3 =&gt; G--DCBA
// 4 =&gt; GF--CB-
// 5 =&gt; GF-DC-A
// 6 =&gt; GFEDC-A
// 7 =&gt; ----CBA
// 8 =&gt; GFEDCBA
// 9 =&gt; GF-DCBA

// <a href="http://www.theelectronicshobbyist.com/blog/goto/uno" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/uno';return true;" onmouseout="self.status=''">Arduino</a> digital pins used to light up
// corresponding segments on the LED display
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define F 7
#define G 8

// Pushbutton connected to pin 9
#define BUTTON 9

int count = 0; // current display count

const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010,
0b0000010, 0b1111000, 0b0000000, 0b0010000 };

void setup() {
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(BUTTON, INPUT);
  lightSegments(0b1000000);
}

void loop() {
  int val = digitalRead(BUTTON);
  if (val == HIGH) {
    count++;
    if (count == 10) count = 0;
    delay(200);
    lightSegments(numbers[count]);
  }
}

void lightSegments(byte number) {
  for (int i = 0; i &lt; 7; i++) {
    int bit = bitRead(number, i);
    // segments connected to Arduino pins 2-8
    digitalWrite(i+2, bit);
  }
}</pre>
<p>Watch <a href="http://www.youtube.com/watch?v=oL84Wo9PNYs" target="_blank">a short video</a> of this project in action.</p>
<p>You might also enjoy:<ol>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-3-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 3'>Controlling a Seven-Segment Display Using Arduino Part 3</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-with-buttons/' rel='bookmark' title='Arduino 2-Digit 7-Segment Display with Buttons | Part 4'>Arduino 2-Digit 7-Segment Display with Buttons | Part 4</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/arduino-2-digit-7-segment-display-counter/' rel='bookmark' title='Arduino 2-Digit 7-Segment Display Counter | Part 1'>Arduino 2-Digit 7-Segment Display Counter | Part 1</a></li>
<li><a href='http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-2-of-4/' rel='bookmark' title='Controlling a Seven-Segment Display Using Arduino Part 2'>Controlling a Seven-Segment Display Using Arduino Part 2</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-4-of-4/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.theelectronicshobbyist.com @ 2012-02-06 22:20:02 -->
