You are on page 1of 6

/* Make Projects: How to Drive a 7 Segment LED URL: By: Riley Porter This is an introduction on how to drive a 7 Segment

LED using only a Arduino. This is not the best way to do this. This is meant to be a learning excercise. In later tutorials I will show you how to use an dedicated IC using SPI or a Shift Register. Enjoy. digitalWrite(8, HIGH) = turn off the "A" segment in the LED display digitalWrite(9, LOW) = turn on the "B" segment in the LED display */ /* This numbers #define #define #define #define #define #define #define */ piece wasn't working, lots of weird errors, so I changed to the real pin A B C D E F G 8 9 2 3 4 5 6

void clr() { //Clears the LED digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); } void char_A() { digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, }

LOW); HIGH); HIGH); HIGH); HIGH); HIGH); HIGH);

void char_B() { //Displays B digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH);

digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2,

HIGH); LOW); LOW); HIGH);

void char_C() { //Displays C digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void char_D() { //Displays D digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void char_E() { //Displays E digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void char_F() { //Displays F digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void one() { //Displays 1

HIGH); HIGH); HIGH); LOW); HIGH); LOW); LOW);

HIGH); HIGH); LOW); HIGH); LOW); HIGH); HIGH);

HIGH); HIGH); HIGH); HIGH); HIGH); LOW); LOW);

LOW); HIGH); HIGH); HIGH); HIGH); LOW); LOW);

digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void two() { //Displays 2 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void three() { //Displays 3 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void four() { //Displays 4 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void five() { //Displays 5 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void six()

LOW); HIGH); HIGH); LOW); LOW); LOW); LOW);

HIGH); HIGH); LOW); HIGH); HIGH); HIGH); LOW);

HIGH); LOW); LOW); HIGH); HIGH); HIGH); HIGH);

LOW); LOW); HIGH); HIGH); LOW); HIGH); HIGH);

HIGH); LOW); HIGH); HIGH); HIGH); LOW); HIGH);

{ //Displays 6 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void seven() { //Displays 7 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void eight() { //Displays 8 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void nine() { //Displays 9 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } void zero() { //Displays 0 digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(8, digitalWrite(9, digitalWrite(2, } HIGH); HIGH); HIGH); HIGH); HIGH); LOW); HIGH);

LOW); LOW); LOW); LOW); HIGH); HIGH); HIGH);

HIGH); HIGH); HIGH); HIGH); HIGH); HIGH); HIGH);

HIGH); LOW); HIGH); HIGH); HIGH); HIGH); HIGH);

HIGH); HIGH); HIGH); LOW); HIGH); HIGH); HIGH);

void LoopDisplay() { //Loop through all Chars and Numbers char_A(); delay(1000); char_B(); delay(1000); char_C(); delay(1000); char_D(); delay(1000); char_E(); delay(1000); char_F(); delay(1000); one(); delay(1000); two(); delay(1000); three(); delay(1000); four(); delay(1000); five(); delay(1000); six(); delay(1000); seven(); delay(1000); eight(); delay(1000); nine(); delay(1000); zero(); delay(1000); } void setup() { //Setup our pins pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); clr(); // There wasn't a call for this function so I just thought here would be the best place to clear the pins Serial.begin(9600); //Begin serial communcation } void loop() { Serial.println("Starting\n"); LoopDisplay();