// Reset counting ke 50
counting = 50;
}
}
}
// Fungsi interrupt untuk Dipsw_2
void dipsw2Interrupt() {
// Membaca status Dipsw_2
dipsw_2_state = digitalRead(DIPSW_2_PIN);
// Setelah interrupt, reset counting ke 50 dan hentikan motor selama 3 detik
counting = 50;
digitalWrite(MOTOR_OUT1_PIN, LOW);
digitalWrite(MOTOR_OUT2_PIN, LOW#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] = {
{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()
{
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 && sw2 == LOW && sw3 == 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 (sw4 == LOW) {
if (millis() - lastTime > 2000) { // Debouncing
lastTime = millis();
digitalWrite(D2, HIGH);
digitalWrite(D1, LOW);
for (int i = 3; i >= 0; i--) {
number(i);
delay(200); // Delay agar Anda bisa melihat perubahan digit
}
delay(1000); // Jeda 1 detik
// Menampilkan angka 2, 0, 0, 3 dengan jeda masing-masing angka 0.2 detik
int numbers[] = {2, 0, 0, 3};
for (int i = 0; i < 4; i++) {
number(numbers[i]);
delay(200); // Jeda 0.2 detik setiap angka
}
}
}
}
Tidak ada komentar:
Posting Komentar