49
Knight Rider display on 6 LEDs
*/
void setup() {
// set up pins 3 to 8 as outputs
for (int i = 3; i <= 8; i++) {
pinMode(i, OUTPUT);
}
}
// function to switch all LEDs off
void allLEDsOff(void)
{
for (int i = 3; i <= 8; i++) {
digitalWrite(i, LOW);
}
}
void loop() {
// move
on LED to the right
for (int i = 3; i <= 8; i++) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(200);
}
// move on LED to the left
for (int i = 8; i > 2; i--) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(200);
}
}
Dasturni
Arduino ga yuklang va agar tuzilgan zanjir to`g`ri bo`lsa
ushbu
dastur ishini boshlaydi va yorug`lik diodlari ketma-ket yonib-o`chishni boshlaydi.
Shuni ham aytish mumkinki, dastur kodini o`zgartirish orqali yorug`lik
diodlarni yonib-o`chish ketma-ketliklarini boshqarish mumkin.