byte D1 = 2;
byte D2 = 3;
byte D3 = 4;
byte D4 = 5;
byte A = 6;
byte B = 7;
byte C = 8;
byte D = 9;
byte E = 10;
byte F = 11;
byte G = 12;
byte DP = 13; // decimal point
// Define the input pins for the 7-segment display segments.
const int segmentPins[] = {A, B, C, D, E, F, G, DP};
// angka 0 = 11111100 //Common Katoda
// angka 1 = 01100000
// angka 2 = 11011010
// angka 3 = 11110010
// angka 4 = 01100110
// angka 5 = 10110110
// angka 6 = 10111100
// angka 7 = 11100000
// angka 8 = 11111100
// angka 9 = 11110100
// Define the input pins for the 7-segment display digits.
const int digitPins[] = {D1, D2, D3, D4};
// For common cathode
uint8_t digitON = LOW;
uint8_t digitOFF = HIGH;
uint8_t segmentON = HIGH;
uint8_t segmentOFF = LOW;
void setup() {
// Pin initialization.
for (int i = 0; i < 8; i++) {
pinMode(segmentPins[i], OUTPUT);
}
for (int i = 0; i < 4; i++) {
pinMode(digitPins[i], OUTPUT);
digitalWrite(digitPins[i], digitOFF);
}
}
void loop()
{
// Digit pertama
for (int i = 0; i < 7; i++){
digitalWrite(segmentPins[i], bitRead(0b11111100, 7 - i) == 1 ? segmentON : segmentOFF);
}
digitalWrite(D1, digitON); // Nyalakan digit ke 1
delay(10); // Tambahkan delay untuk mengatur tingkat kecerahan
// ===== Digit ke 2 =====
digitalWrite(D1, digitOFF); // Matikan digit ke 1
// We iterate through each of the segments of the second digit. We use the same approach as before to set the appropriate segments for the number '2'
for (int i = 0; i < 7; i++){
digitalWrite(segmentPins[i], bitRead(0b11110110, 7 - i) == 1 ? segmentON : segmentOFF);
}
digitalWrite(D2, digitON);
delay(10);
digitalWrite(D2, digitOFF);
// =====Digit ketiga ======
for (int i = 0; i < 7; i++){
digitalWrite(segmentPins[i], bitRead(0b11011010, 7 - i) == 1 ? segmentON : segmentOFF);
}
digitalWrite(D3, digitON); // Nyalakan digit ke 3
delay(10); // Tambahkan delay untuk mengatur tingkat kecerahan
// ===== Digit ke 3 =====
digitalWrite(D3, digitOFF); // Matikan digit ke 3
// =====Digit keempat ======
for (int i = 0; i < 7; i++){
digitalWrite(segmentPins[i], bitRead(0b11100000, 7 - i) == 1 ? segmentON : segmentOFF);
}
digitalWrite(D4, digitON); // Nyalakan digit ke 3
delay(10); // Tambahkan delay untuk mengatur tingkat kecerahan
// ===== Digit ke 3 =====
digitalWrite(D4, digitOFF); // Matikan digit ke 3
}