Created
April 12, 2019 09:45
-
-
Save idriszmy/7684f45ef6703887258da21e36c1e5aa to your computer and use it in GitHub Desktop.
Mengawal pin keluaran pada Maker UNO yang bersambung dengan LED.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Fungsi kod: Mengawal pin pada Maker UNO seterusnya | |
membuat kelipan LED. | |
Penulis: Idris Zainal Abidin | |
Blog: https://idrisz.my | |
Kemaskini: 12 April 2019 | |
*/ | |
int pin = 0; | |
void setup() | |
{ | |
for (pin = 2; pin < 14; pin++) { | |
// Tetapkan pin 2 sehingga 13 sebagai pin keluaran | |
pinMode(9, OUTPUT); | |
} | |
} | |
void loop() | |
{ | |
for (pin = 2; pin < 14; pin++) { | |
if (pin % 2 == 0) { | |
// Menghantar isyarat HIGH (voltan 5V) | |
// pada pin genap seterusnya menyalakan LED | |
digitalWrite(pin, HIGH); | |
} | |
else { | |
// Menghantar isyarat LOW (voltan 5V) | |
// pada pin ganjil seterusnya memadamkan LED | |
digitalWrite(pin, LOW); | |
} | |
} | |
delay(500); // Tunggu 500 mili saat (atau 0.5 saat) | |
for (pin = 2; pin < 14; pin++) { | |
if (pin % 2 == 0) { | |
// Menghantar isyarat LOW (voltan 5V) | |
// pada pin genap seterusnya memadamkan LED | |
digitalWrite(pin, LOW); | |
} | |
else { | |
// Menghantar isyarat HIGH (voltan 5V) | |
// pada pin ganjil seterusnya menyalakan LED | |
digitalWrite(pin, HIGH); | |
} | |
} | |
delay(500); // Tunggu 500 mili saat (atau 0.5 saat) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment