Zadatak 2: Napravite trčeće svijetlo. Neka se LED diode uključuju s lijeva na desno i svaka neka bude uključena pola sekunde.
Sketch
int led1 = 8;
int led2 = 9;
int led3 = 10;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for half a second
digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for half a second
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for half a second
digitalWrite(led3, LOW); // turn the LED off by making the voltage LOW
}
Na početku loop dijela uključili smo prvu LED diodu, potom smo čekali 500 milisekundi te smo isključili prvu LED diodu. Postupak smo ponovili za drugu i treću LED diodu i time smo postigli efekt trčećih LED dioda.
POVEZNICE:
Kako započeti rad s mikrokontolerom?
Upravljanje LED diodama
Blink na 3 LED diode
Trčeće svijetlo - verzija 1
Trčeće svijetlo - verzija 2
Nema komentara:
Objavi komentar