Dastur kodi: #define A 8 #define B 7 #define C 6 #define D 5 #define E 4 #define F 3 #define G 2 #define BUTTON 12 byte v = 0; void setup() { pinMode(A, OUTPUT); pinMode(B, OUTPUT); pinMode(C, OUTPUT); pinMode(D, OUTPUT); pinMode(E, OUTPUT); pinMode(F, OUTPUT); pinMode(G, OUTPUT); pinMode(BUTTON, INPUT); } void loop() { digitalWrite(A, LOW); // Z HARIFI digitalWrite(B, HIGH); digitalWrite(C, HIGH); digitalWrite(D, HIGH); digitalWrite(E, HIGH); digitalWrite(F, LOW); digitalWrite(G, HIGH); if (digitalRead(BUTTON) == HIGH) { delay(500); v = 1; } while (v == 1) { digitalWrite(A, HIGH); // A HARIFI digitalWrite(B, HIGH); digitalWrite(C, HIGH); digitalWrite(D, LOW); digitalWrite(E, HIGH); digitalWrite(F, HIGH); digitalWrite(G, LOW); if (digitalRead(BUTTON) == HIGH) { delay(500); v = 2; } } while (v == 2) {// R HARIFI digitalWrite(A, HIGH); // digitalWrite(B, HIGH); digitalWrite(C, HIGH); digitalWrite(D, LOW); digitalWrite(E, HIGH); digitalWrite(F, HIGH); digitalWrite(G, HIGH); if (digitalRead(BUTTON) == HIGH) { delay(500); v = 3; } } while (v == 3) { digitalWrite(A, HIGH); // I HARIFI digitalWrite(B, HIGH); digitalWrite(C, LOW); digitalWrite(D, LOW); digitalWrite(E, LOW); digitalWrite(F, LOW); digitalWrite(G, LOW); if (digitalRead(BUTTON) == HIGH) { delay(500); v = 0; } } while (v == 4) { // F digitalWrite(A, LOW); digitalWrite(B, LOW); digitalWrite(C, LOW); digitalWrite(D, LOW); digitalWrite(E, LOW); digitalWrite(F, LOW); digitalWrite(G, HIGH); if (digitalRead(BUTTON) == HIGH) { delay(1000); v = 0; } } }
https://www.tinkercad.com/things/aT0PL7c5W1Gbrilliantwolt/editel?sharecode=pxeR5IHe2yB5M7EQhtdjE3Fl_dgpZTr93u2IAk7_wjE
1-qadam. Laboratoriya ishini bajarish uchun ulanish sxemasi tashkil qilamiz. Birinchi navbatda led lampalarni ulashning strukturaviy sxemasi chiziladi (1.1-chizmada keltirilgan).
1.1-chizma. Led lampalarni ulashning strukturaviy sxemasi.
2-qadam. Bu qadamda laboratoriya ishini amaliyotda qo’llash uchun elektron sxemasi chizamiz (1.2-chizmada keltirilgan).
3-qadam. Laboratoriya ishining strukturaviy va elektron sxemasi yordamida Tinkercad.com platformasida ishni emulatsion formasini xosil qilamiz(1.3-chizma).
Kode qismi:
int push_button = 8;
int b=0;
int a=0;
int A_1=1;
int B_2=2;
int C_3=3;
int D_4=4;
int E_5=5;
int F_6=6;
int G_7=7;
void setup() {
pinMode(push_button, INPUT);
pinMode(A_1,OUTPUT);
pinMode(B_2,OUTPUT);
pinMode(C_3,OUTPUT);
pinMode(D_4,OUTPUT);
pinMode(E_5,OUTPUT);
pinMode(F_6,OUTPUT);
pinMode(G_7,OUTPUT);
}
void loop() {
a = digitalRead(push_button);
if(a==1){
b=b+1;
}
delay(200);
if(b==0){
digitalWrite(A_1, HIGH);
digitalWrite(B_2, HIGH);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, HIGH);
digitalWrite(E_5, HIGH);
digitalWrite(F_6, HIGH);
digitalWrite(G_7, LOW);
delay(50);
}
else if(b==1){
digitalWrite(A_1, LOW);
digitalWrite(B_2, HIGH);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, LOW);
digitalWrite(E_5, LOW);
digitalWrite(F_6, LOW);
digitalWrite(G_7, LOW);
delay(50);
}
else if(b==2){
digitalWrite(A_1, HIGH);
digitalWrite(B_2, HIGH);
digitalWrite(C_3, LOW);
digitalWrite(D_4, HIGH);
digitalWrite(E_5, HIGH);
digitalWrite(F_6, LOW);
digitalWrite(G_7, HIGH);
delay(50);
}
else if(b==3){
digitalWrite(A_1, HIGH);
digitalWrite(B_2, HIGH);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, HIGH);
digitalWrite(E_5, LOW);
digitalWrite(F_6, LOW);
digitalWrite(G_7, HIGH);
delay(50);
}
else if(b==4){
digitalWrite(A_1, LOW);
digitalWrite(B_2, HIGH);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, LOW);
digitalWrite(E_5, LOW);
digitalWrite(F_6, HIGH);
digitalWrite(G_7, HIGH);
delay(50);
}
else if(b==5){
digitalWrite(A_1, HIGH);
digitalWrite(B_2, LOW);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, HIGH);
digitalWrite(E_5, LOW);
digitalWrite(F_6, HIGH);
digitalWrite(G_7, HIGH);
delay(50);
}
else if(b==6){
digitalWrite(A_1, HIGH);
digitalWrite(B_2, LOW);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, HIGH);
digitalWrite(E_5, HIGH);
digitalWrite(F_6, HIGH);
digitalWrite(G_7, HIGH);
delay(50);
}
else if(b==7){
digitalWrite(A_1, HIGH);
digitalWrite(B_2, HIGH);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, LOW);
digitalWrite(E_5, LOW);
digitalWrite(F_6, LOW);
digitalWrite(G_7, LOW);
delay(50);
}
else if(b==8){
digitalWrite(A_1, HIGH);
digitalWrite(B_2, HIGH);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, HIGH);
digitalWrite(E_5, HIGH);
digitalWrite(F_6, HIGH);
digitalWrite(G_7, HIGH);
delay(50);
}
else if(b==9){
digitalWrite(A_1, HIGH);
digitalWrite(B_2, HIGH);
digitalWrite(C_3, HIGH);
digitalWrite(D_4, HIGH);
digitalWrite(E_5, LOW);
digitalWrite(F_6, HIGH);
digitalWrite(G_7, HIGH);
delay(50);
}
else if(b==10){
b=0;
}
}
Dastur linki::::
https://www.tinkercad.com/things/bBSgCcp4rKK-copy-of-7-segment/editel?sharecode=nj7fQnHVPZi-gaFFlcdpc6Beb6dG17Y0I6C2zxIi0Vw
Xulosa:
Men ushbu topshiriqni bajarish davomida 7 segment tugma orqali boshqarishni o’rgandim. Yuqoridagi rasmda umumiy katodli (minus) bitta raqamli yetti segmentli indikatorning pinouti ko‘rsatilgan. Modul - bu yettita LEDni (shu tufayli indikator o‘z nomini oldi) va nuqta shaklidagi sakkizinchi LEDni o‘z ichiga olgan kichik LED ko‘rsatkich. LEDlarni Arduinodan boshqa ketma -ketlikda yoqish orqali siz turli raqamlarni ko‘rsatishingiz mumkin.E'tibor bering, panelda qarshilik yo‘q, shuning uchun LEDlarni ulashda tashqi rezistorlardan foydalaning. Agar umumiy anodli yetti segmentli indikatorning pinouti siz uchun tushunarsiz bo‘lsa, unda siz quvvatni turli pimlarga ulash orqali pinoutni empirik tarzda o‘rnatishingiz mumkin. Agar noto‘g‘ri yoqilsa, hech qanday dahshatli narsa bo‘lmaydi, lekin rezistorsiz LEDlar yonib ketishi mumkin.
1-qadam. Laboratoriya ishini bajarish uchun ulanish sxemasi tashkil qilamiz. Birinchi navbatda led lampalarni ulashning strukturaviy sxemasi chiziladi (1.1-chizmada keltirilgan).
1.1-chizma. Led lampalarni ulashning strukturaviy sxemasi.
Do'stlaringiz bilan baham: |