<?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; bits</title>
	<atom:link href="http://www.theelectronicshobbyist.com/blog/tag/bits/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>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:18:59 -->
