const uint8_t segment_digits[10] = {
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111 // 9
};
void setup() {
DDRD = 0xFF; // إعداد جميع الأزرار كمخرج
}
void display_digit(uint8_t digit) {
PORTD = segment_digits[digit]; // عرض الرقم
}
void loop() {
static uint8_t counter = 0; // استخدام static للحفاظ على القيمة بين الدورات
static int8_t direction = 1; // الاتجاه
display_digit(counter);
delay(1000); // تأخير لمدة ثانية
// تحديث العداد
counter += direction;
// عكس الاتجاه عند الوصول للنهايات
if (counter == 9 || counter == 0) {
direction = -direction;
}
}