const int redLedPin = 9; // Qizil chiroqning pin raqami
const int yellowLedPin = 10; // Sariq chiroqning pin raqami
const int greenLedPin = 11; // Yashil chiroqning pin raqami
const int buttonPin = 2; // Knopkaning pin raqami
void setup() {
Serial.begin(9600);
Serial.println("salom");
pinMode(redLedPin, OUTPUT); // Qizil chiroqni chiqish sifatida sozlash
pinMode(yellowLedPin, OUTPUT); // Sariq chiroqni chiqish sifatida sozlash
pinMode(greenLedPin, OUTPUT); // Yashil chiroqni chiqish sifatida sozlash
pinMode(buttonPin, INPUT); // Knopkani kirish sifatida sozlash
}
int count = 0;
int dd=0;
int lastState = LOW;
void loop() {
if(digitalRead(buttonPin)==1)
{
Serial.println("tugma bosildi");
}
int value = digitalRead((buttonPin));
if (lastState != value)
{
lastState = value;
if (value == HIGH)
{
//tugmacha bosilganda
count++;
Serial.println(count);
if (count > 1) {
count = 0; // Agar count 2 dan katta bo'lsa, uni nolga qaytarib boshlash
}
}
}
if (value == LOW)
{
//tugmacha quyib yuborilganda
}
if (count == 0)
{
// Qizil chiroqni yonsin
digitalWrite(redLedPin, HIGH);
delay(2000);
digitalWrite(redLedPin, LOW);
// Sariq chiroqni yonsin
digitalWrite(yellowLedPin, HIGH);
delay(2000);
digitalWrite(yellowLedPin, LOW);
// Yashil chiroqni yonsin
digitalWrite(greenLedPin, HIGH);
delay(2000);
digitalWrite(greenLedPin, LOW);
}
if (count == 1)
{
dd++;
if(dd>1)
{
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(greenLedPin, HIGH);
}
else
{
// Qizil chiroqni yonsin
digitalWrite(redLedPin, HIGH);
delay(2000);
digitalWrite(redLedPin, LOW);
// Sariq chiroqni yonsin
digitalWrite(yellowLedPin, HIGH);
delay(2000);
digitalWrite(yellowLedPin, LOW);
// Yashil chiroqni yonsin
digitalWrite(greenLedPin, HIGH);
delay(2000);
digitalWrite(greenLedPin, LOW);
}
}
}