Arduino IDE orqali svetodiodlar yordamida svetofor dasturini tuzing. Ranglar almashinish intervalini 5 sekund deb belgilang
const int redLED = 10;
const int yellowLED = 9;
const int greenLED = 8;
void setup() {
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
void loop() {
digitalWrite(redLED, HIGH); // Qizil yorug'lik yonaydi
digitalWrite(yellowLED, LOW); // Sariq yorug'lik yo'q
digitalWrite(greenLED, LOW); // Yashil yorug'lik yo'q
delay(5000); // 5
sekund kutamiz
//
Sariq svetofor
digitalWrite(redLED, LOW); // Qizil yorug'lik yo'q
digitalWrite(yellowLED, HIGH); // Sariq yorug'lik yonaydi
digitalWrite(greenLED, LOW); // Yashil yorug'lik yo'q
delay(5000); // 5
sekund kutamiz
//
Yashil svetofor
digitalWrite(redLED, LOW); // Qizil yorug'lik yo'q
digitalWrite(yellowLED, LOW); // Sariq yorug'lik yo'q
digitalWrite(greenLED, HIGH); // Yashil yorug'lik yonaydi
delay(5000); // 5 sekund kutamiz
}