7 Segment Two Digits Cathode Type
1. Objective
The objective is talk about, Use 7 segment 2 digits cathode type display count up number.
2. Requirement
- Arduino Uno x1
- USB Cable x1 (No need in simulation)
- Breadboard x1 (No need in simulation)
- 7 Segment 2 digits x1 (Cathode Type)
- Resistor 220Ohm x2
- Electronic Wire (No need in simulation)
3. Build Circuit
Build circuit like Figure 1.
Segment Pin A to Arduino pin 13
Segment Pin B to Arduino pin 12
Segment Pin C to Arduino pin 11
Segment Pin D to Arduino pin 10
Segment Pin E to Arduino pin 9
Segment Pin F to Arduino pin 8
Segment Pin G to Arduino pin 7
Segment Pin D1 to Arduino pin 6
Segment Pin D2 to Arduino pin 5
*Note you must find pin A, B, C, D, E, F, G, D1 and D2 in real 7 segment because the pin are not order as simulation.
4. Coding
// by Tann Thona
// 7 Segment 2 digits cathode
int pinA = 13;
int pinB = 12;
int pinC = 11;
int pinD = 10;
int pinE = 9;
int pinF = 8;
int pinG = 7;
int D2 = 6;
int D1 = 5;
int j = 0;
int i = 0;
int k = 0;
int Arduino_Pins[7] = {pinA, pinB, pinC, pinD, pinE, pinF, pinG}; // an array of pin numbers to which LEDs
int Segment_Pins[10][7] = {{1, 1, 1, 1, 1, 1, 0}, // 0
{0, 1, 1, 0, 0, 0, 0}, // 1
{1, 1, 0, 1, 1, 0, 1}, // 2
{1, 1, 1, 1, 0, 0, 1}, // 3
{0, 1, 1, 0, 0, 1, 1}, // 4
{1, 0, 1, 1, 0, 1, 1}, // 5
{1, 0, 1, 1, 1, 1, 1}, // 6
{1, 1, 1, 0, 0, 0, 0}, // 7
{1, 1, 1, 1, 1, 1, 1}, // 8
{1, 1, 1, 1, 0, 1, 1}, // 9
};
void setup() {
// put your setup code here, to run once:
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for (int t = 0; t < 20; t++) // int t = 0; t < 500; t++
{
digitalWrite(D1, 0);
digitalWrite(D2, 1);
for (j = 0; j < 7; j++)
{
digitalWrite(Arduino_Pins[j], Segment_Pins[i][j]);
}
delay(100); // delay(1);
digitalWrite(D1, 1);
digitalWrite(D2, 0);
for (j = 0; j < 7; j++)
{
digitalWrite(Arduino_Pins[j], Segment_Pins[k][j]);
}
delay(100); // delay(1);
i++;
if (i == 9)
{
i = 0;
k++;
if (k == 9)
{
k = 0;
}
}
}
}
Click here to download code and simulation file
4. Result
According to code above,7 segment is display with count up number from 0 to 99 in loop.Watch Video Explain in Khmer
YouTube: ICT4D-KH
Copyright By Tann Thona
No comments:
Post a Comment