Modul 3-1
MODULE 3: SEVEN SEGMENT DISPLAYS
Introduction to the basics of seven-segment displays.
Focus on using an Arduino for displaying numbers on a TM1637 seven-segment display.
OBJECTIVE
Seven Segment Displays
Introduce basic principles of seven-segment displays.
COMPONENTS USED
Arduino Uno
Arduino Shield
TM1637 Seven Segment Display
Button
Buzzer
INTRODUCTION TO SEVEN SEGMENT DISPLAYS
Common Anode Display: All positive ends (anodes) connected to one pin; negative ends (cathodes) connected to ground.
Common Cathode Display: Negative ends (cathodes) of lights connected to one pin; positive ends (anodes) powered to light segments.
Structure: Seven individual LEDs arranged to resemble the digit '8'.
Common applications: calculators, clocks, elevators due to cost-effectiveness and usability.
DISPLAYING NUMBERS AND LETTERS
Logic for segment activation:
In a Common Cathode (CC) display, a segment turns on with a LOW (0) signal.
In a Common Anode (CA) display, a segment turns on with a HIGH (1) signal.
Capabilities: Can display numbers 0-9 and some letters A-Z through appropriate segment lighting.
EXAMPLE: DISPLAY ON SEVEN SEGMENT DISPLAYS
Using TM1637 display driver to control the seven-segment display.
Ensure connection of the display to the Arduino as per the schematic.
CODE EXAMPLE 1: DISPLAY ON SEVEN SEGMENT DISPLAYS
#include <TM1637Display.h>
#define CLK 3
#define DIO 2
int num = 0;
TM1637Display display(CLK, DIO);
void setup() {
display.setBrightness(5);
}
void loop() {
for(num=0;num<=9;num++) {
display.showNumberDec(num,true);
delay(500);
}
if(num>9) {
display.clear();
uint8_t data[] = { SEG_G, /* Display sequence data */ };
for(int i=0; i<5; i++) {
display.setSegments(data);
delay(400);
display.clear();
delay(250);
}
num == 10;
}
for(num=10;num>=0;num--) {
display.showNumberDec(num,true);
delay(500);
}
}PRACTICAL EXERCISE
Create a countdown system utilizing the seven-segment displays that counts until it reaches 9.
Display “FULL” when attempting to exceed this count.
CODE EXAMPLE: COUNTING ON SEVEN SEGMENT DISPLAYS
#include <TM1637Display.h>
#define CLK 8
#define DIO 7
#define SW1 3
#define SW2 2
#define BUZZER 5
int num = 0;
bool sw1Pressed = false;
bool sw2Pressed = false;
TM1637Display display(CLK, DIO);
void setup() {
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
pinMode(BUZZER, OUTPUT);
display.setBrightness(5);
Serial.begin(9600);
}
void loop() {
bool sw1State = digitalRead(SW1) == LOW;
bool sw2State = digitalRead(SW2) == LOW;
if (sw1State && !sw1Pressed) {
sw1Pressed = true;
num++;
if (num > 9) {
displayFullMessage();
} else {
display.showNumberDec(num, true);
Serial.println(num);
}
} else if (!sw1State) {
sw1Pressed = false;
}
if (sw2State && !sw2Pressed) {
sw2Pressed = true;
num--;
if (num < 0) {
num = 0;
}
display.showNumberDec(num, true);
Serial.println(num);
} else if (!sw2State) {
sw2Pressed = false;
}
}
// Function to display "FULL" message
void displayFullMessage() {
num = 9;
display.clear();
uint8_t data[] = { /* Display sequence for FULL message */ };
for (int i = 0; i < (sizeof(data) - 3); i++) {
display.setSegments(data + i);
delay(500);
}
...
}CONCLUSION
The module teaches the use of seven-segment displays integrated with Arduino programming.
Students complete a hands-on project: a simple counter limited to 9.
Encourages project customization and fosters learning in electronics and programming.