Me and My Arduino Uno



Arduino Uno with Breadboard wired up to run a 7 Segment LED.


Wiring looks (and is) messy, due to the strange layout of the pins.
Arduino and breadboard with 7-segment LED wired up.
The code shown below runs on an Arduino Uno to drive a 7 segment LED from Radio Shack (276-075 which is a National Semiconductor one: ELS321HDB/A) very different from the ones you see in the Arduino tutorials.

// Arduino 7 segment display example software
// http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html
// License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
// --------------------------------------------------------------------
// common anode section and in-code comments added by Clair Dunn 12/2011


// Define the LED digit patters, from 0 - 9
// Note that these patterns are for common cathode displays
// For common anode displays, change the 1's to 0's and 0's to 1's
// 1 = LED on, 0 = LED off, in this order:

//                                    Arduino pin: 2,3,4,5,6,7,8

/*If you were using a common anode LED you would use this section
byte seven_seg_digits[10][7] = { { 0,0,0,0,0,0,1 },  // = 0 x
                                      { 1,0,0,1,1,1,1 },  // = 1 x
                                      { 0,0,1,0,0,1,0 },  // = 2 x
                                      { 0,0,0,0,1,1,0 },  // = 3 x
                                      { 1,0,0,1,1,0,0 },  // = 4 x
                                      { 0,1,0,0,1,0,0 },  // = 5 x
                                      { 0,1,0,0,0,0,0 },  // = 6 x
                                      { 0,0,0,1,1,1,1 },  // = 7 x
                                      { 0,0,0,0,0,0,0 },  // = 8 x
                                      { 0,0,0,1,1,0,0 }   // = 9 x
                                       };
*/

//                                    Arduino pin: 2,3,4,5,6,7,8

 byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 },  // = 0
                                      { 0,1,1,0,0,0,0 },  // = 1
                                      { 1,1,0,1,1,0,1 },  // = 2
                                      { 1,1,1,1,0,0,1 },  // = 3
                                      { 0,1,1,0,0,1,1 },  // = 4
                                      { 1,0,1,1,0,1,1 },  // = 5
                                      { 1,0,1,1,1,1,1 },  // = 6
                                      { 1,1,1,0,0,0,0 },  // = 7
                                      { 1,1,1,1,1,1,1 },  // = 8
                                      { 1,1,1,0,0,1,1 }   // = 9
                                       };

// set the Arduino pins connected to the LED segments on Radio Shack 276-075
// which is National Semiconductor ELS-321HDB/A (very different from
// standard 7-seg display
// comment list below is LED pin# > Arduino pin# | segment name

void setup() {
  pinMode(2, OUTPUT);  //14 > 2 A
  pinMode(3, OUTPUT);  //13 > 3 B
  pinMode(4, OUTPUT);  // 8 > 4 C
  pinMode(5, OUTPUT);  // 7 > 5 D
  pinMode(6, OUTPUT);  // 6 > 6 E
  pinMode(7, OUTPUT);  // 2 > 7 F
  pinMode(8, OUTPUT);  // 1 > 8 G
  pinMode(9, OUTPUT);  //RDP> 9 decimal point
  writeDot(0);  // start with the "dot" off
}

void writeDot(byte dot) {
  digitalWrite(9, dot); // decimal point - pin 9 on Arduino
}

void sevenSegWrite(byte digit) {
  byte pin = 2; // Arduino pin where the segment list starts
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}

// displays digits from 9 to 0
void loop() {
  for (byte count = 10; count > 0; --count) {
   delay(1000);
   sevenSegWrite(count - 1);
  }
  delay(4000);
}