2. Buat program menggunakan Arduino IDE.
3. Transfer program yang telah dibuat ke Arduino Uno.
4. Uji coba program pada rangkaian percobaan sesuai dengan kondisi yang
diinginkan.
5. Proses selesai setelah uji coba berhasil dilakukan.
#define a 6
#define b 7
#define c 8
#define d 9
#define e 10
#define f 11
#define g 12
#define dp 13
#define D1 4
#define D2 5
#define Dsw1 A0
#define Dsw2 A1
#define Dsw3 A2
#define Dsw4 A3
bool sw1,sw2,sw3,sw4;
int segments[] = {a,b,c,d,e,f,g};
byte digitPatterns[10][7] = {
{0, 0, 0, 0, 0, 0, 1}, // 0
{1, 0, 0, 1, 1, 1, 1}, // 1
{0, 0, 1, 0, 0, 1, 0}, // 2
{0, 0, 0, 0, 1, 1, 0}, // 3
{1, 0, 0, 1, 1, 0, 0}, // 4
{0, 1, 0, 0, 1, 0, 0}, // 5
{0, 1, 0, 0, 0, 0, 0}, // 6
{0, 0, 0, 1, 1, 1, 1}, // 7
{0, 0, 0, 0, 0, 0, 0}, // 8
{0, 0, 0, 0, 1, 0, 0} // 9
};
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(segments[i], OUTPUT);
}
pinMode(dp, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(Dsw1, INPUT_PULLUP);
pinMode(Dsw2, INPUT_PULLUP);
pinMode(Dsw3, INPUT_PULLUP);
pinMode(Dsw4, INPUT_PULLUP);
Serial.begin(9600);
}
void number(int display) {
if (display >= 0 && display <= 9) {
for (int i = 0; i < 7; i++) {
digitalWrite(segments[i], digitPatterns[display][i]);
}
}
}
void loop() {
int sw1 = digitalRead(Dsw1);
int sw2 = digitalRead(Dsw2);
int sw3 = digitalRead(Dsw3);
int sw4 = digitalRead(Dsw4);
static int digit = 1; // Digit yang sedang ditampilkan (1 atau 2)
static int count = 0; // Counter untuk digit
static unsigned long lastTime = 0; // Waktu terakhir pembacaan tombol
if (sw1 == LOW) {
if (millis() - lastTime > 1000) { // Debouncing
lastTime = millis();
count++;
if (count > 9) {
count = 0;
}
if (digit == 1) {
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
number(count);
digit = 2;
} else {
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
number(count);
digit = 1;
}
}
}
else if (sw2 == LOW) {
if (millis() - lastTime > 1000) { // Debouncing
lastTime = millis();
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
for (int i = 9; i >= 0; i--) {
number(i);
delay(1000); // Delay agar Anda bisa melihat perubahan digit
}
}
}
if (sw3 == LOW) {
if (millis() - lastTime > 2000) { // Debouncing
lastTime = millis();
count++;
if (count > 9) {
count = 0;
}
if (digit == 1) {
digitalWrite(D2, HIGH);
digitalWrite(D1, LOW);
number(count);
digit = 2;
} else {
digitalWrite(D2, LOW);
digitalWrite(D1, HIGH);
number(count);
digit = 1;
}
}
}
else if (sw4 == LOW) {
if (millis() - lastTime > 2000) { // Debouncing
lastTime = millis();
digitalWrite(D2, HIGH);
digitalWrite(D1, LOW);
for (int i = 9; i >= 0; i--) {
number(i);
delay(200); // Delay agar Anda bisa melihat perubahan digit
}
}
}
}
6. Video Demo[Kembali]