#include <LiquidCrystal_I2C.h>
int segmentPins[] = {22, 23, 24, 25, 26, 27, 28, 29};
byte numbers[4] = {
B11011001, // Angka 5
B01111011, // Angka 0
B11111011, // Angka 8
B11011011 // Angka 9
};
int currentDigit = 0;
const int numDigits = 4;
const int delayTime = 1000;
unsigned long previousMillis = 0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte customChar0[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00011,
};
byte customChar1[8] = {
0b00000,
0b01100,
0b10010,
0b10010,
0b10001,
0b01000,
0b11100,
0b00000,
};
byte customChar2[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b10000,
0b01000,
0b00110,
};
byte customChar3[8] = {
0b00100,
0b00011,
0b00100,
0b00011,
0b00100,
0b00011,
0b00010,
0b00001,
};
byte customChar4[8] = {
0b00000,
0b11000,
0b00000,
0b11000,
0b00000,
0b11000,
0b00001,
0b11110,
};
byte customChar5[8] = {
0b00010,
0b00010,
0b00010,
0b00010,
0b00010,
0b01110,
0b10000,
0b00000,
};
char namaDepan[] = "DIYU"; // Ganti dengan nama depan Anda
int count = 10;
void setup() {
lcd.init();
lcd.backlight();
lcd.begin(16, 2);
lcd.createChar(0, customChar0);
lcd.createChar(1, customChar1);
lcd.createChar(2, customChar2);
lcd.createChar(3, customChar3);
lcd.createChar(4, customChar4);
lcd.createChar(5, customChar5);
for (int i = 0; i < 8; i++) {
pinMode(segmentPins[i], OUTPUT);
}
Serial.begin(9600);
Serial.println("Mikrokontroler: 22.11.5089");
lcd.setCursor(0, 0);
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(2));
lcd.setCursor(0, 1);
lcd.write(byte(3));
lcd.write(byte(4));
lcd.write(byte(5));
lcd.setCursor(4, 0);
lcd.print("DIYU ");
}
void loop() {
if (Serial.available() > 0) {
String input = Serial.readString();
input.trim();
if (input.equalsIgnoreCase("mulai")) {
while (count >= 0) {
lcd.setCursor(4, 1);
lcd.print(count);
Serial.println(count);
displayNumber(numbers[currentDigit]);
currentDigit = (currentDigit + 1) % numDigits;
delay(1000);
count--;
}
}
}
}
void displayNumber(byte number) {
for (int i = 0; i < 8; i++) {
digitalWrite(segmentPins[i], bitRead(number, i));
}
}