Arduino deneyi 15
Single-Digit 7-Segment Display
Intermediate · 60 min · Output arrays
Display the digits 0–9 on a common-cathode 7-segment display.
Malzemeler
- Arduino Uno
- Common-cathode 7-segment display
- 7 × 220 Ω resistors
- Breadboard and jumper wires
Bağlantı
- Use the display datasheet to identify segments a–g and the common cathodes.
- Connect segments a–g through individual 220 Ω resistors to pins 2–8.
- Connect both common cathode pins to GND.
Kod
const int segPins[7] = {2,3,4,5,6,7,8};
const byte digits[10][7] = {
{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},
{0,1,1,0,0,1,1},{1,0,1,1,0,1,1},{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},
{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}
};
void showDigit(int n) {
for (int i=0; i<7; i++) digitalWrite(segPins[i], digits[n][i]);
}
void setup() { for (int p : segPins) pinMode(p, OUTPUT); }
void loop() { for (int n=0; n<10; n++) { showDigit(n); delay(1000); } }
Ne olmalı?
The display counts from 0 to 9 and repeats.
Meydan okuma
Add two buttons to move the number up and down.
Güvenlik ve sorun giderme
- Bağlantıyı değiştirmeden önce gücü kes.
- Her LED ile direnç kullan.
- Kart ve port seçimini Arduino IDE'de kontrol et.
- Her kablonun koddaki pin numarasıyla eşleştiğini doğrula.
Not: Ders metinleri İngilizcedir. Orijinal Türkçe çalışma kâğıdı PDF olarak indirilebilir.
