Arduino Activity 06 - Seven-Segment LED Count-Down Timer
Arduino Activity 06 - Seven-Segment LED Count-Down Timer
Dept. of RAISE
Robotics Training – Beginner Level 1 (Arduino)
HOW IT WORKS:
A seven-segment LED display shows a single digit or character
using LED segments. Each segment is an individual LED, and by
controlling which segments are lit at any time, we can display
numeric values. We’re using a single-digit display in this
project, shown in Figure, but there are also two-, three-, four-
, and eight-digit variations available.
This project will create a simple timer to count down from 9 to 0. The seven-segment
LED has 10 pins. Seven pins control the seven LEDs that light up to form each digit,
and the eighth pin controls the decimal point.
The other two pins are the common-cathode (–) or common-anode (+) pins, which
add power to the project. Our seven-segment LED is a common cathode, meaning
one side of each LED needs to connect to the ground. It’s important to note that the
code will work only with a common-cathode LED. If you have a common-anode LED you want to use, check the
troubleshooting section at the end of this chapter before uploading the sketch. Each LED segment requires a resistor
to limit the current; otherwise, it will burn out. The pins are labeled with a letter, as shown in Figure 3-2. The
numbered pins control the segments as shown on the right. The Arduino creates the number by turning the LEDs
off or on in different combinations.
THE BUILD:
digitalWrite(9, dot);
}
void loop() {
for (byte count = 10; count > 0; --count) { // Start the countdown
delay(1000); // 1 second between each digit
sevenSegWrite(count - 1); // Counting down by 1
}
delay(4000);
}
Task 1:
pinMode(9, OUTPUT);
writeDot(0); // Start with the decimal point off
serial.begin(9600);
digit = 0;
}
void loop() {
digit = serial.parseint();