Arduino - Seven Segment - Alphabets

Looping through A to F using arrays to display on the Seven-segment display.

Getting Started

First, we must define the following:

Letter Array
A 1,1,1,0,1,1,1
b 0,0,1,1,1,1,1
C 1,0,0,1,1,1,0
d 0,1,1,1,1,0,1
E 1,0,0,1,1,1,1
F 1,0,0,0,1,1,1

0 = Off, 1 = On

Seven-Segment Order

The above image is the order of segments in which determines the order of the values inside the array of letters.

Initialization

Lets write our two arrays and variable.

int pins[7] = {2,3,4,5,6,7,8};
int letters[][7] = { { 1,1,1,0,1,1,1 }, //a
                     { 0,0,1,1,1,1,1 }, //b
                     { 1,0,0,1,1,1,0 }, //c
                     { 0,1,1,1,1,0,1 }, //d
                     { 1,0,0,1,1,1,1 }, //e
                     { 1,0,0,0,1,1,1 }  //f
                   };
int length_pins = 7; //number (length) of pins inside the pins array
int length_letters = 6; //number (length) of elements inside the letters array

By default in Arduino, we need to write our setup() and loop() functions.

void setup(){
    Serial.begin(9600); \\opens the serial port @ 9600bps
}

void loop(){

}

setup()

Lets setup the setup() function that includes a for loop to register each pin and print it to the console.

void setup(){
    Serial.begin(9600); \\opens the serial port @ 9600bps
    for(int ctr = 0; ctr < length_pins; ctr++){
        pinMode(pins[ctr],OUTPUT);
        Serial.println(pins[ctr]);
    }
}

loop()

Lets setup the loop() function that calls a custom function draw() to use digitalWrite() to display specific pins or letters in this case. Delay between each draw() of the letters so the human eye can witness the looping A through F.

void loop(){
  for (int ctr = 0; ctr < length_letters; ctr++) {
    draw(ctr); 
    delay(1000);
  }
}

draw()

Lets setup the draw() function that gets called from loop(). It will light up the specific segments requested by the letters array.

void draw(int number){  
  for (int j=0; j < length_letters; j++) {
   digitalWrite(pins[j], letters[number][j]);
  }
}