Guruh talabasi Xodjamberdiyev Dilshodning Avtomatlashtirilgan loyihalash fanidan bajargan 3-modul topshirig’i



Yüklə 21,33 Kb.
tarix27.12.2023
ölçüsü21,33 Kb.
#199099
Avtomatlashgan 3 modul


111-20 guruh talabasi Xodjamberdiyev Dilshodning Avtomatlashtirilgan loyihalash fanidan bajargan 3-modul topshirig’i

  1. LED-ni yoqish va o'chirish uchun quyidagi kodni Arduinoga yozing:

const int LED_PIN = 2; // LED-ni ulash uchun pin raqami
const int RESISTOR_VALUE = 220; // Resistorning ohm qiymati

void setup() {
pinMode(LED_PIN, OUTPUT); // LED pinini chiqishga to'g'riylash
}

void loop() {
digitalWrite(LED_PIN, HIGH); // LED-ni yoqish
delay(1000); // 1 sekund kutamiz
digitalWrite(LED_PIN, LOW); // LED-ni o'chirish
delay(1000); // 1 sekund kutamiz
}

  1. Arduino platasi svetadiodning davrini 1 sekundga sozlash uchun quyidagi kodni ishlating:

const int LED_PIN = 2; // LED-ni ulash uchun pin raqami

void setup() {
pinMode(LED_PIN, OUTPUT); // LED pinini chiqishga to'g'riylash
}

void loop() {
digitalWrite(LED_PIN, HIGH); // LED-ni yoqish
delay(1000); // 1 sekund kutamiz
digitalWrite(LED_PIN, LOW); // LED-ni o'chirish
delay(1000); // 1 sekund kutamiz
}

  1. Do, re, mi ohanglarini zummerda hosil qilish uchun quyidagi kodni ishlating:

const int GREEN_LED_PIN = 2; // Yashil svetadiodning pin raqami
const int RED_LED_PIN = 3; // Qizil svetadiodning pin raqami
const int NOTE_DURATION = 500; // To'liq tovush davomiyligi (millyonida mikrosaniya cinsida)

void setup() {
pinMode(GREEN_LED_PIN, OUTPUT); // Yashil svetadiod pinini chiqishga to'g'riylash
pinMode(RED_LED_PIN, OUTPUT); // Qizil svetadiod pinini chiqishga to'g'riylash
}

void loop() {
digitalWrite(GREEN_LED_PIN, HIGH); // Yashil svetadiodni yoqish
delay(NOTE_DURATION); // To'vush davomiyligini kutyapmiz
digitalWrite(GREEN_LED_PIN, LOW); // Yashil svetadiodni o'chirish
delay(NOTE_DURATION); // To'vush davomiyligini kutyapmiz
digitalWrite(RED_LED_PIN, HIGH); // Qizil svetadiodni yoqish
delay(NOTE_DURATION); // To'vush davomiyligini kutyapmiz
digitalWrite(RED_LED_PIN, LOW); // Qizil svetadiodni o'chirish
delay(NOTE_DURATION); // To'vush davomiyligini kutyapmiz
}

  1. Do, re, mi, fa, sol, la, si ohanglarini zummerda hosil qilish uchun quyidagi kodni ishlating:

const int LED_PIN = 2; // Svetadiodning pin raqami
const int NOTE_DURATION = 500; // To'liq tovush davomiyligi (millyonida mikrosaniya cinsida)

void setup() {
pinMode(LED_PIN, OUTPUT); // Svetadiod pinini chiqishga to'g'riylash
}

void loop() {
digitalWrite(LED_PIN, HIGH); // Svetadiodni yoqish
delay(NOTE_DURATION); // To'vush davomiyligini kutyapmiz
digitalWrite(LED_PIN, LOW); // Svetadiodni o'chirish
delay(NOTE_DURATION / 2); // To'vush davomiyligi / 2 ni kutyapmiz
}

  1. Yangi yil musiqasini zummer musiqasini yaratish uchun notalarni va davomiylarni to'g'ri kelishuvda to'g'ri kelishuvda yozing. Misol uchun, quyidagi kod yangi yil musiqasini zummerda ijro etadi:

const int BUZZER_PIN = 2; // Zummersh pin raqami

// Notalar va davomiylar
const int notes[] = {NOTE_E5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_G5, NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_E5, NOTE_D5, NOTE_D5};
const int durations[] = {200, 200, 400, 200, 200, 400, 200, 200, 400, 200, 200, 400, 200, 200, 400};

void setup() {
pinMode(BUZZER_PIN, OUTPUT); // Zummersh pinini chiqishga to'g'riylash
}

void loop() {
for (int i = 0; i < sizeof(notes) / sizeof(notes[0]); i++) {
int noteDuration = 1000 / durations[i]; // Davomiylarni millisekundga aylantiramiz
tone(BUZZER_PIN, notes[i], noteDuration); // Notalarni ijro etamiz
delay(noteDuration * 1.3); // Nota davomiyligining 1.3 baravaridan keyin kutyapmiz
noTone(BUZZER_PIN); // Zummershni o'chiramiz
delay(50); // Har bir nota orasida 50 millisekund kutamiz
}
}

  1. Temperatura va namlikni o'qish uchun DHT sensorini (masalan, DHT11 yoki DHT22) ulang. Temperatura va namlikni har tomonlama o'qish uchun DHT bibliotekasidan foydalanish kerak. Quyidagi kodni ishlating:


#include // DHT bibliotekasini ulaymiz

#define DHT_PIN 2 // DHT sensorining ulangan pin raqami
#define DHT_TYPE DHT11 // DHT sensorining turi (DHT11 yoki DHT22)

DHT dht(DHT_PIN, DHT_TYPE); // DHT obyektini yaratamiz

void setup() {
Serial.begin(9600); // Serial kommunikatsiyani yoqing
dht.begin(); // DHT sensorini ishga tushiramiz
}

void loop() {
delay(2000); // 2 sekund kutamiz
float temperature = dht.readTemperature(); // Temperaturani o'qimiz
float humidity = dht.readHumidity(); // Namlikni o'qimiz
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println("%");
}
Yüklə 21,33 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin