<?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; pins</title>
	<atom:link href="http://www.theelectronicshobbyist.com/blog/tag/pins/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>Arduino LED Control Using DIP Switch &#124; Part 1</title>
		<link>http://www.theelectronicshobbyist.com/blog/arduino-led-control-using-dip-switch/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/arduino-led-control-using-dip-switch/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 05:00:48 +0000</pubDate>
		<dc:creator>Natalia</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[DIP switch]]></category>
		<category><![CDATA[LED]]></category>
		<category><![CDATA[pins]]></category>
		<category><![CDATA[serial communication]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=356</guid>
		<description><![CDATA[This is a very simple project that controls a set of LEDs using a DIP switch. The purpose of the sketch is to show the use of some Arduino serial communication functions, and to increase familiarity interfacing with digital I/O pins. Two LEDs were connected to the RX and TX pins on the Arduino (digital [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/09/dipleds.jpg"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-medium wp-image-357" title="dipleds" src="http://www.theelectronicshobbyist.com/blog/wp-content/uploads/2010/09/dipleds-234x300.jpg" alt="LED control using DIP switch" width="234" height="300" /></a>This is a very simple project that controls a set of LEDs using a DIP switch. The purpose of the sketch is to show the use of some <a href="http://www.theelectronicshobbyist.com/blog/2010/08/arduino-serial-communication/" target="_self">Arduino serial communication</a> functions, and to increase familiarity interfacing with digital I/O pins.</p>
<p>Two LEDs were connected to the RX and TX pins on the Arduino (digital pins 0 and 1), but remember to disconnect these pins while the sketch is being uploaded.</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=4304&amp;affiliate_banner_id=1" target="_blank">Breadboard</a></li>
<li>8 <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4215&amp;affiliate_banner_id=1" target="_blank">LEDs</a>, assorted colors</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 wire, assorted lengths</a></li>
<li><a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4318&amp;affiliate_banner_id=1" target="_blank">DIP switch</a></li>
<li>6 <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4383&amp;affiliate_banner_id=1" target="_blank">10K Ohm resistors</a> (pull up)</li>
<li>8 <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4373&amp;affiliate_banner_id=1" target="_blank">100 Ohm resistors</a> (current limiting)</li>
</ul>
<p><span id="more-356"></span></p>
<p>Sketch:</p>
<pre>// www.TheElectronicsHobbyist.com/blog
// Natalia Fargasch Norman
// LED control via DIP switches

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

// <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 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;

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);
  // setup serial port
  Serial.begin(9600);
  Serial.println("Serial port open");
}

void loop() {
  s1state = digitalRead(S1);
  digitalWrite(LED1, s1state);
  s2state = digitalRead(S2);
  digitalWrite(LED2, s2state);
  s3state = digitalRead(S3);
  digitalWrite(LED3, s3state);
  s4state = digitalRead(S4);
  digitalWrite(LED4, s4state);
  s5state = digitalRead(S5);
  digitalWrite(LED5, s5state);
  s6state = digitalRead(S6);
  digitalWrite(LED6, s6state);
  Serial.print(s1state);
  Serial.print(s2state);
  Serial.print(s3state);
  Serial.print(s4state);
  Serial.print(s5state);
  Serial.print(s6state);
  Serial.println();
}</pre>
<p>A <a href="http://www.youtube.com/watch?v=SVVMeKMTtH8" target="_blank">video</a> of the project in action.</p>
<p>You might also enjoy:<ol>
<li><a href='http://www.theelectronicshobbyist.com/blog/led-patterns-using-dip-switch-and-arduino/' rel='bookmark' title='LED Patterns Using DIP Switch and Arduino'>LED Patterns Using DIP Switch and Arduino</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/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/' 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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/arduino-led-control-using-dip-switch/feed/</wfw:commentRss>
		<slash:comments>3</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>
		<item>
		<title>Controlling a Seven-Segment Display Using Arduino Part 3</title>
		<link>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-3-of-4/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-3-of-4/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 07:00:01 +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[LED]]></category>
		<category><![CDATA[pins]]></category>
		<category><![CDATA[sketch]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=19</guid>
		<description><![CDATA[The second sketch cycles through the numbers from 0 to 9, but only increments the display counter each time a button is pressed. Note that this code includes simple debouncing by introducing a short delay when the Arduino detects that the button has been pressed. Sketch #2: // www.TheElectronicsHobbyist.com/blog // Natalia Fargasch Norman // Seven-segment [...]]]></description>
			<content:encoded><![CDATA[<p></p><div class="separator" style="clear: both; text-align: center;"><a style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" href="http://www.theelectronicshobbyist.com/images/Seven-Segment.jpg"><img src="http://www.theelectronicshobbyist.com/images/Seven-Segment.jpg" border="0" alt="" width="162" height="200" /></a></div>
<p>The second sketch cycles through the numbers from 0 to 9, but only increments the display counter each time a button is pressed. Note that this code includes simple debouncing by introducing a short delay when the <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4221&amp;affiliate_banner_id=1" target="_blank">Arduino</a> detects that the button has been pressed.</p>
<p><span id="more-19"></span></p>
<p>Sketch #2:</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; ABCDEF
// 1 =&gt; BC
// 2 =&gt; ABDEG
// 3 =&gt; ABCDG
// 4 =&gt; BCFG
// 5 =&gt; ACDFG
// 6 =&gt; ACDEFG
// 7 =&gt; ABC
// 8 =&gt; ABCDEFG
// 9 =&gt; ABCDFG

// <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

// Common anode;
// on when pin is low
// and off when pin is high
#define ON LOW
#define OFF HIGH

int count = 0; // current display count
int val = 0;   // digital input from button

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);
  zero();
}

void loop() {
  val = digitalRead(BUTTON);
  if (val == HIGH) {
    count++;
    delay(200);
    switch (count) {
      case 0:
        zero();
        break;
      case 1:
        one();
        break;
      case 2:
        two();
        break;
      case 3:
        three();
        break;
      case 4:
        four();
        break;
      case 5:
        five();
        break;
      case 6:
        six();
        break;
      case 7:
        seven();
        break;
      case 8:
        eight();
        break;
      case 9: {
        nine();
        count = -1;
        break;
      }
    }
  }
}

// 0 =&gt; ABCDEF
void zero() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, ON);
  digitalWrite(F, ON);
  digitalWrite(G, OFF);
}

// 1 =&gt; BC
void one() {
  digitalWrite(A, OFF);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, OFF);
  digitalWrite(E, OFF);
  digitalWrite(F, OFF);
  digitalWrite(G, OFF);
}

// 2 =&gt; ABDEG
void two() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, OFF);
  digitalWrite(D, ON);
  digitalWrite(E, ON);
  digitalWrite(F, OFF);
  digitalWrite(G, ON);
}

// 3 =&gt; ABCDG
void three() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, OFF);
  digitalWrite(F, OFF);
  digitalWrite(G, ON);
}

// 4 =&gt; BCFG
void four() {
  digitalWrite(A, OFF);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, OFF);
  digitalWrite(E, OFF);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
}

// 5 =&gt; ACDFG
void five() {
  digitalWrite(A, ON);
  digitalWrite(B, OFF);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, OFF);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
}

// 6 =&gt; ACDEFG
void six() {
  digitalWrite(A, ON);
  digitalWrite(B, OFF);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, ON);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
}

// 7 =&gt; ABC
void seven() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, OFF);
  digitalWrite(E, OFF);
  digitalWrite(F, OFF);
  digitalWrite(G, OFF);
}

// 8 =&gt; ABCDEFG
void eight() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, ON);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
}

// 9 =&gt; ABCDFG
void nine() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, OFF);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
}</pre>
<p>You might also enjoy:<ol>
<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/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>
<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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-3-of-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Controlling a Seven-Segment Display Using Arduino Part 2</title>
		<link>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-2-of-4/</link>
		<comments>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-2-of-4/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 15:00:00 +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[pins]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[supplies]]></category>

		<guid isPermaLink="false">http://www.theelectronicshobbyist.com/blog/?p=17</guid>
		<description><![CDATA[This month&#8217;s project is a simple program to display the Arabic numbers using the Arduino and a 7-segment display. Parts list: Arduino Duemilanove 7-Segment Display(I got the grab bag, with 50 displaysfor $10.95) Breadboard Mini Push Button Switch Jumper Wire The 7-segment display used in this example is a common anode display with pin connections [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>This month&#8217;s project is a simple program to display the Arabic numbers using the <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4221&amp;affiliate_banner_id=1" target="_blank">Arduino</a> and a 7-segment display.</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.avantlink.com/click.php?tt=cl&amp;mi=10609&amp;pw=21273&amp;url=http%3A%2F%2Fwww.jameco.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProductDisplay%3FlangId%3D-1%26storeId%3D10001%26catalogId%3D10001%26productId%3D1955790" target="_blank">7-Segment Display<img style="border: 0px;" src="http://www.avantlink.com/tpv/10609/0/17253/21273/-/cl/image.png" alt="" width="0" height="0" /></a>(I got the <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">grab bag, with 50 displays<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 $10.95)</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%2FProductDisplay%3FlangId%3D-1%26storeId%3D10001%26catalogId%3D10001%26productId%3D20601" target="_blank">Breadboard<img style="border: 0px;" 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=4211&amp;affiliate_banner_id=1" target="_blank">Mini Push Button Switch</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 Wire</a></li>
</ul>
<p><span id="more-17"></span></p>
<div class="separator" style="clear: both; text-align: center;"><a style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" href="http://www.theelectronicshobbyist.com/images/7segpins.jpg"><img src="http://www.theelectronicshobbyist.com/images/7segpins.jpg" border="0" alt="" /></a></div>
<p>The 7-segment display used in this example is a common anode display with pin connections as shown in the picture, and the <a href="http://www.cutedigi.com/product_info.php?ref=3&amp;products_id=4221&amp;affiliate_banner_id=1" target="_blank">Arduino</a> sketches were written so as to light up a segment when the corresponding pin is LOW.</p>
<p>The first of a series of three simple sketches cycles through the numbers from 0 to 9, resets the display to show a &#8220;0&#8243; once it reaches &#8220;9&#8243; and repeats until the power is turned off on the Arduino. The code below accomplishes this in a very simplified manner, as each digit is formed by a separate function that sequentially lights up each of the necessary segments to display that number.</p>
<p>The third sketch in this sequence will use individual bits to represent each segment and will require less written code, a good thing to keep in mind when programming microcontrollers, as they have a small memory footprint (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.theelectronicshobbyist.com/blog/goto/duemilanove" style="" target="_blank" rel="nofollow" onmouseover="self.status='http://www.theelectronicshobbyist.com/blog/goto/duemilanove';return true;" onmouseout="self.status=''">Duemilanove</a> has 32K bytes of program memory).</p>
<p>Sketch #1:</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; ABCDEF
// 1 =&gt; BC
// 2 =&gt; ABDEG
// 3 =&gt; ABCDG
// 4 =&gt; BCFG
// 5 =&gt; ACDFG
// 6 =&gt; ACDEFG
// 7 =&gt; ABC
// 8 =&gt; ABCDEFG
// 9 =&gt; ABCDFG

// Arduino 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

// Common anode;
// on when pin is low
// and off when pin is high
#define ON LOW
#define OFF HIGH

int ms = 1000;

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

void loop() {
  zero();
  one();
  two();
  three();
  four();
  five();
  six();
  seven();
  eight();
  nine();
}

// 0 =&gt; ABCDEF
void zero() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, ON);
  digitalWrite(F, ON);
  digitalWrite(G, OFF);
  delay(ms);
}

// 1 =&gt; BC
void one() {
  digitalWrite(A, OFF);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, OFF);
  digitalWrite(E, OFF);
  digitalWrite(F, OFF);
  digitalWrite(G, OFF);
  delay(ms);
}

// 2 =&gt; ABDEG
void two() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, OFF);
  digitalWrite(D, ON);
  digitalWrite(E, ON);
  digitalWrite(F, OFF);
  digitalWrite(G, ON);
  delay(ms);
}

// 3 =&gt; ABCDG
void three() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, OFF);
  digitalWrite(F, OFF);
  digitalWrite(G, ON);
  delay(ms);
}

// 4 =&gt; BCFG
void four() {
  digitalWrite(A, OFF);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, OFF);
  digitalWrite(E, OFF);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
  delay(ms);
}

// 5 =&gt; ACDFG
void five() {
  digitalWrite(A, ON);
  digitalWrite(B, OFF);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, OFF);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
  delay(ms);
}

// 6 =&gt; ACDEFG
void six() {
  digitalWrite(A, ON);
  digitalWrite(B, OFF);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, ON);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
  delay(ms);
}

// 7 =&gt; ABC
void seven() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, OFF);
  digitalWrite(E, OFF);
  digitalWrite(F, OFF);
  digitalWrite(G, OFF);
  delay(ms);
}

// 8 =&gt; ABCDEFG
void eight() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, ON);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
  delay(ms);
}

// 9 =&gt; ABCDFG
void nine() {
  digitalWrite(A, ON);
  digitalWrite(B, ON);
  digitalWrite(C, ON);
  digitalWrite(D, ON);
  digitalWrite(E, OFF);
  digitalWrite(F, ON);
  digitalWrite(G, ON);
  delay(ms);
}</pre>
<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/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/' 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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.theelectronicshobbyist.com/blog/controlling-a-seven-segment-display-using-arduino-part-2-of-4/feed/</wfw:commentRss>
		<slash:comments>5</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:18:19 -->
