Laboratory Manual 2016 Edition
Laboratory Manual 2016 Edition
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
Laboratory Exercise 6
7-Segment and Dot Matrix LED
Objectives:
At the end of the exercise, the students should be able to:
• interface 7 Segment display to Arduino board
• interface 8x8 Dot Matrix to Arduino board
• add library file to a sketch
• describe the functions of an 595 Shift Register
Materials:
1 – Arduino UNO R3 Starter Kit
1 – Personal Computer with installed Arduino IDE
Software
7-Segment Display
Seven segment displays are used in many embedded
system and industrial applications where the range of
outputs to be shown is known beforehand. Basic 1 digit
seven segment display can show numbers from 0-9 and a
few characters. 7 segment displays are of different types;
especially they differ in the number of digits/character it
can display. Basically a 7 segment display is a single unit,
which can display only 1 digit or 1 character. More digits
are displayed by multiplexing single unit 7 segment
displays together to form 2 digit display, 3 digit display or
4 digit 7 segment display. Its quiet easy to interface
Arduino and 7 Segment display together!
Single-Digit 7 Segment Display
3.8.com
E G DF
Com DP
MCU1
ArduinoUno
10
PowerJack
DISP
Extemal
ArduinoUNO
void setup() {
pinMode(seg_a,OUTPUT); //
configure all pins used to outputs
pinMode(seg_b,OUTPUT);
pinMode(seg_c,OUTPUT);
pinMode(seg_d,OUTPUT);
pinMode(seg_e,OUTPUT);
pinMode(seg_f,OUTPUT);
pinMode(seg_g,OUTPUT);
pinMode(seg_dp,OUTPUT);
pinMode(com,OUTPUT);
void loop() {
digitalWrite(com,HIGH); // set
common anode HIGH (5V)
for (int i = 0; i < 10; i++) { //
count 0 - 9
switch(i){ // switch statemet to
select the number
case 1:
digitalWrite(seg_a,HIGH);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,HIGH);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,HIGH);
digitalWrite(seg_g,HIGH);
digitalWrite(seg_dp,HIGH);
break;
case 2:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,HIGH);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,LOW);
digitalWrite(seg_f,HIGH);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;
case 3:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,HIGH);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;
case 4:
digitalWrite(seg_a,HIGH);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,HIGH);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;
case 5:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,HIGH);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;
case 6:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,HIGH);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,LOW);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;
case 7:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,HIGH);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,HIGH);
digitalWrite(seg_g,HIGH);
digitalWrite(seg_dp,HIGH);
break;
case 8:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,LOW);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;
case 9:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;
}
delay(1000); // Show each number
for 1 second
}
}
4-Digit 7-Segment Display
Now we are going to see how to interface 4 digit 7
segment display with arduino. We are going to use a
different method to control this Four digit display. Let’s
see the pinout of this 4 digit 7 segment display.
void loop() {
t.update(); //timer update
if (Serial.available()) { // read
from serial
t.stop(timer_event); //stop timer
if anythign to read
cathode_high(); // blank the screen
String s = Serial.readString();
//read the serail value
number = (long)s.toInt(); //convert
it to int
if (number > 9999) { //check the
number is 0-9999
Serial.println("Please Enter
Number Between 0 - 9999");
} else {
break_number(number);
timer_event = t.every(1,
display_number); // start timer again
}
}
}
void break_number(long num) { //
seperate the input number into 4
single digits
first_digit = num / 1000;
digits[0] = first_digit;
int first_left = num - (first_digit *
1000);
second_digit = first_left / 100;
digits[1] = second_digit;
int second_left = first_left -
(second_digit * 100);
third_digit = second_left / 10;
digits[2] = third_digit;
fourth_digit = second_left -
(third_digit * 10);
digits[3] = fourth_digit;
}
void display_number() { //scanning
cathode_high(); //black screen
digitalWrite(latch, LOW); //put the
shift register to read
shiftOut(data, clk, LSBFIRST,
numbers[digits[count]]); //send the
data
digitalWrite(CAS[count], LOW); //turn
on the relevent digit
digitalWrite(latch, HIGH); //put the
shift register to write mode
count++; //count up the digit
if (count == 4) { // keep the count
between 0-3
count = 0;
}
}
void cathode_high() { //turn off all 4
digits
digitalWrite(CA_1, HIGH);
digitalWrite(CA_2, HIGH);
digitalWrite(CA_3, HIGH);
digitalWrite(CA_4, HIGH);
}
void setup() {
Serial.begin(9600); // Serial begin
pinMode(latchPin, OUTPUT); // Pin
configuration
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
for (int i = 0; i < 8; i++) { // for
loop is used to configure
//common cathodes
pinMode(pins[i], OUTPUT);
digitalWrite(pins[i], HIGH);
}
}
void loop() {
for (int k = 0; k < 1000; k++) { //
showing each letter for 1 second
display_char(A);
}
shiftOut(dataPin, clockPin,
LSBFIRST, ch[j]);
digitalWrite(latchPin, HIGH);
//delay(1);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin,
LSBFIRST, B00000000); // to get rid
//of
flicker when
digitalWrite(latchPin, HIGH);
digitalWrite(pins[j], HIGH);
}
}
Laboratory Task:
References: