Created
February 17, 2025 03:30
-
-
Save justmangoou/c3df011eeb47effc3acfb8d1c4c723c8 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
const int MAX_PIN = 13; | |
const int MIN_PIN = 4; | |
int index = MAX_PIN, currentFill = MIN_PIN; | |
void setup() { | |
for (int id = MAX_PIN; id >= MIN_PIN; id--) { | |
pinMode(id, OUTPUT); | |
} | |
} | |
void loop() { | |
if (currentFill == MAX_PIN) { | |
// Trường hợp đầy sẽ reset lại toàn bộ đèn và delay 0.5s trước khi vào chu kì mới | |
index = MAX_PIN; | |
currentFill = MIN_PIN; | |
for (int id = MAX_PIN; id >= MIN_PIN; id--) { | |
digitalWrite(id, LOW); | |
} | |
delay(500); | |
} else if (index < currentFill) { | |
index = MAX_PIN; | |
currentFill++; | |
} | |
digitalWrite(index, HIGH); | |
delay(100); | |
if (index != currentFill) { | |
digitalWrite(index, LOW); | |
} | |
index--; | |
// Hiển thị các đèn đã fill | |
for (int i = MIN_PIN; i < currentFill; i++) { | |
digitalWrite(i, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment