Ulanish
Ushbu tajribada 7-segmentli displeyning har bir AG pinini mos ravishda bitta
200 ohm oqim cheklovchi qarshilikka ulang va keyin 4-11 pinga ulang. GND GND
ga ulanadi. Dasturlash orqali biz mos keladigan LED (lar) ni yoqish uchun pin4-11
ning bir yoki bir nechtasini Yuqori darajali qilib sozlashimiz mumkin.
7 segmentli displey va SunFounder Uno platasi orasidagi simlar:
7-segmentli displey
Arduino Uno
A
7
B
6
C
5
D.
11
E
10
F
8
G
9
DP
4
Kom
GND
ulanish diagrammasi
2- rasm. 7 segmentli displayni ulanish diagrammasi
Dasur kodi esa quydagicha bo’ladi
7
int a=7;
int b=6;
int c=5;
int d=11;
int e=10;
int f=8;
int g=9;
int dp=4;
// 1
void display1(void)
{
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
}
//
void display2(void)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
}
// 3
void display3(void)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(g,HIGH);
}
// 4
void display4(void)
{
digitalWrite(f,HIGH);
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
8
}
// 5
void display5(void)
{
digitalWrite(a,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
}
// 6
void display6(void)
{
digitalWrite(a,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
}
// 7
void display7(void)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
}
// 8
void display8(void)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
}
9
void clearDisplay(void)
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
}
void display9(void)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(f,HIGH);
}
void display0(void)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
}
void setup()
{
int i;
for(i=4;i<=11;i++)
pinMode(i,OUTPUT);
}
void loop()
{
while(1)
{ clearDisplay();
display0();
10
delay(2000);
clearDisplay();
display1();
delay(2000);
clearDisplay();
display2();
delay(2000);
clearDisplay();
display3();
delay(2000);
clearDisplay();
display4();
delay(2000);
clearDisplay();
display5();
delay(2000);
clearDisplay();
display6();
delay(2000);
clearDisplay();
display7();
delay(2000);
clearDisplay();
display8();
delay(2000);
clearDisplay();
display9();
delay(2000);
}
}
11
7 segmentli displayni ulanish diagrammasini ulab oldik
7 segmentli displayni ulanish diagrammasida jatijalar quydagicha chiqdi.
12
Dostları ilə paylaş: |