Laboratoriyaning amaliy qismi.
Modelning Arduinoga ulanish sxemasi:
Quyidagi misolda indikatorda raqamlarni almashtirish faqat taktika tugmasi bosilganda sodir bo‘ladi. 3 -raqamga yetib, taymer nolga qaytariladi va tugmani ikkinchi bosilishini kutadi. Bu Arduino uchun juda oddiy dasturlar va yetti segmentli ko‘rsatkich; murakkab va qiziqarli dasturlar uchun siz Arduino uchun 74hc595 smenali registrni ishlatishingiz kerak.
Ushbu model uchun quyidagi dastur mos keladi:
#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, HIGH); //nol raqami
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
if (digitalRead(BUTTON) == HIGH) { delay(500); v = 1; }
while (v == 1) {
digitalWrite(A, LOW); //bir raqami
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
if (digitalRead(BUTTON) == HIGH) { delay(500); v = 2; }
}
while (v == 2) {
digitalWrite(A, HIGH); //ikki raqami
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
if (digitalRead(BUTTON) == HIGH) { delay(500); v = 3; }
}
while (v == 3) {
digitalWrite(A, HIGH); //uch raqami
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
if (digitalRead(BUTTON) == HIGH) { delay(500); v = 0; }
}
}
Kodga tushuntirishlar: o‘zgaruvchan bayt v = 0; dasturda bir vaqtdan ikkinchisiga o‘tish uchun ishlatiladi. Tugma bosilganda v o‘zgaruvchining qiymati o‘zgaradi; bir davradan ikkinchisiga tez o‘tishdan himoya qilish uchun dasturning har bir shartida kichik kechikish bor.
Dostları ilə paylaş: |