const int button1Pin = 2; // Birinchi knopka pin raqami
const int button2Pin = 3; // Ikkinchi knopka pin raqami
const int redLedPin = 9; // Qizil LED pin raqami
const int greenLedPin = 10; // Yashil LED pin raqami
const int yellowLedPin = 11; // Sariq LED pin raqami
void setup() {
pinMode(button1Pin, INPUT); // Birinchi knopkani kiritish uchun pin raqamini kirish sifatida sozlash
pinMode(button2Pin, INPUT); // Ikkinchi knopkani kiritish uchun pin raqamini kirish sifatida sozlash
pinMode(redLedPin, OUTPUT); // Qizil LED ni chiqarish uchun pin raqamini chiqish sifatida sozlash
pinMode(greenLedPin, OUTPUT); // Yashil LED ni chiqarish uchun pin raqamini chiqish sifatida sozlash
pinMode(yellowLedPin, OUTPUT); // Sariq LED ni chiqarish uchun pin raqamini chiqish sifatida sozlash
}
void loop() {
// Birinchi knopkani tekshirish
if (digitalRead(button1Pin) == HIGH && digitalRead(button2Pin) == LOW) {
digitalWrite(redLedPin, HIGH); // Qizil LEDni yoqish
digitalWrite(greenLedPin, LOW); // Yashil LEDni o'chirish
digitalWrite(yellowLedPin, LOW); // Sariq LEDni o'chirish
}
// Ikkinchi knopkani tekshirish
if (digitalRead(button2Pin) == HIGH && digitalRead(button1Pin) == LOW) {
digitalWrite(redLedPin, LOW); // Qizil LEDni o'chirish
digitalWrite(greenLedPin, HIGH); // Yashil LEDni yoqish
digitalWrite(yellowLedPin, LOW); // Sariq LEDni yoqish
}
if(digitalRead(button1Pin)==HIGH && digitalRead(button2Pin)==HIGH)
{
digitalWrite(redLedPin, LOW); // Qizil LEDni o'chirish
digitalWrite(greenLedPin, LOW); // Yashil LEDni yoqish
digitalWrite(yellowLedPin, HIGH);
}
// Agar hech qaysi knopka bosilmagan bo'lsa, hammasini o'chirish
if (digitalRead(button1Pin) == LOW && digitalRead(button2Pin) == LOW) {
digitalWrite(redLedPin, LOW); // Qizil LEDni o'chirish
digitalWrite(greenLedPin, LOW); // Yashil LEDni o'chirish
digitalWrite(yellowLedPin, LOW); // Sariq LEDni o'chirish
}
}