Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

Close

7_Segment_Red_LED_0_3_Inch_Digital_Display | Electronics Lab

7_Segment_Red_LED_0_3_Inch_Digital_Display
Version 1 - Last update: Oct 4, 2015

By: Darren A. Vozar Date: January 20, 2014 This materiel can be freely used and passed out to anyone! This is a program to run a 7 Segment Red LED 0.3" Digital Display I got Radio Shack. I warn you that I am a novice but the code works. The display is a common cathode design. There are 10 pins on the display starting from the far corner away form the decimal point (when looking at the front the display pin 1 is in the top left hand corner ) ( pins listed as "no pin" are not there ) they are as follows: 1. Anode F = Arduino pin 2 2. Anode G = Arduino pin 3 3. No pin 4. Common Cathode = 1 Hooked to Negative 5. No pin 6. Anode E = Arduino pin 4 7. Anode D = Arduino pin 5 8. Anode C = Arduino pin 6 9. Anode RHDP ( Right Hand Decimal Point ) = Arduino pin 7 10. No pin 11. No pin 12. Common Cathode = 1 Hooked to Negative 13. Anode B = Arduino pin 8 14. Anode A = Arduino pin 9 The common cathode pins are connected to Negative ( only one needs hooked up because they are connected together inside the display ). All of the Anodes need to have a resistor to limit the current. I used 8 - 330 Ohm resistors for this.

/* By: Darren A. Vozar Date: January 21, 2014 Purpos: This is a program to run a LED nummber display */

void setup () { // Create Serial Object Serial.begin (9600);

// Initilize the pins for display as output. pinMode(2, OUTPUT); // Display pin 1 pinMode(3, OUTPUT); // Display pin 2 pinMode(4, OUTPUT); // Display pin 6 pinMode(5, OUTPUT); // Display pin 7 pinMode(6, OUTPUT); // Display pin 8 pinMode(7, OUTPUT); //Display pin 9 pinMode(8, OUTPUT); // Display pin 13 pinMode(9, OUTPUT); //Display pin 14

}

void loop () {

// Have the Arduino wait to receive input while (Serial.available() == 0);

// Read the input int hexInputValue = Serial.read();

int inputValue = hexInputValue - '0';

// Change the display to the number pressed if (inputValue == 1) { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, LOW);

hexInputValue = 0;

}

if (inputValue == 2) { digitalWrite(2, LOW); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, HIGH);

hexInputValue = 0;

}

if (inputValue == 3) { digitalWrite(2, LOW); digitalWrite(3, HIGH); digitalWrite(4, LOW); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, HIGH);

hexInputValue = 0;

}

if (inputValue == 4) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, LOW);

hexInputValue = 0;

}

if (inputValue == 5) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, LOW); digitalWrite(9, HIGH);

hexInputValue = 0;

}

if (inputValue == 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, LOW); digitalWrite(9, HIGH);

hexInputValue = 0;

}

if (inputValue == 7) { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, HIGH);

hexInputValue = 0;

}

if (inputValue == 8) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, HIGH);

hexInputValue = 0;

}

if (inputValue == 9) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, HIGH);

hexInputValue = 0;

}

if (inputValue == 0) { digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, HIGH);

hexInputValue = 0;

}

if (hexInputValue == 46) { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, HIGH); digitalWrite(8, LOW); digitalWrite(9, LOW);

hexInputValue = 46;
inputValue = 0;

}

if (inputValue < 0 || inputValue > 9) { Serial.println("Input Value: "); Serial.println(inputValue); Serial.println("Input is invalid!");
}

}

Comments disabled