// Definisikan pin untuk mengendalikan seven segment
const int segA = 2;
const int segB = 3;
const int segC = 4;
const int segD = 5;
const int segE = 6;
const int segF = 7;
const int segG = 8;
const int segDP = 9; // Segmen titik desimal
void setup() {
// Atur pin sebagai output
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
pinMode(segDP, OUTPUT);
}
void tampilkanAngka(int angka) {
// Matikan semua segmen
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segDP, LOW);
// Tampilkan angka pada seven segment
switch (angka) {
case 1:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segE, HIGH);
break;
case 2:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
digitalWrite(segE, LOW);
break;
case 3:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
digitalWrite(segE, HIGH);
break;
case 4:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segE, HIGH);
break;
case 5:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segE, HIGH);
break;
case 6:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segE, LOW);
break;
case 7:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segE, HIGH);
break;
case 8:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segE, LOW);
break;
case 9:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segE, HIGH);
break;
default:
break;
}
}
void loop() {
// Tampilkan angka dari 1 sampai 9 dengan menyalakan seven segment
for (int i = 1; i <= 9; i++) {
tampilkanAngka(i);
delay(1000); // Tunda satu detik
}
}