Created
November 10, 2024 12:29
-
-
Save antonprafanto/bfb6d24f7ab03ee0905dd9f388555991 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Konstanta, tidak akan berubah. | |
| const int ledPin = 26; // Nomor pin LED | |
| // Variabel yang akan berubah | |
| int ledState = LOW; // Mulai dengan LED mati | |
| // Variabel memegang waktu | |
| unsigned long previousMillis = 0; // Waktu terakhir LED diperbarui | |
| // Konstanta untuk interval | |
| const long interval = 1000; // Interval berkedip (milidetik) | |
| void setup() { | |
| // Atur pin LED sebagai output | |
| pinMode(ledPin, OUTPUT); | |
| } | |
| void loop() { | |
| // Dapatkan waktu saat ini | |
| unsigned long currentMillis = millis(); | |
| // Periksa apakah cukup waktu telah berlalu | |
| if (currentMillis - previousMillis > interval) { | |
| // Simpan waktu ketika LED berkedip | |
| previousMillis = currentMillis; | |
| // Balikkan keadaan LED: nyala jika mati, mati jika nyala | |
| if (ledState == LOW) { | |
| ledState = HIGH; | |
| } else { | |
| ledState = LOW; | |
| } | |
| // Setel LED sesuai dengan ledState | |
| digitalWrite(ledPin, ledState); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment