Created
June 1, 2014 19:22
-
-
Save huytd/ee07fab2e55dc81875d0 to your computer and use it in GitHub Desktop.
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
// khai báo pin 13 | |
const int ledPin = 13; | |
// Các giá trị sẽ thay đổi | |
int ledState = LOW; // ledState - trạng thái của đèn LED | |
long previousMillis = 0; // thời gian của lần vừa xử lý | |
long interval = 1000; // biên độ chênh lệch thời gian - đây sẽ là thời gian cần delay | |
void setup() { | |
// Thiết lập chế độ output cho pin 13 | |
pinMode(ledPin, OUTPUT); | |
} | |
void loop() | |
{ | |
// lấy thời gian hiện tại | |
unsigned long currentMillis = millis(); | |
// tính khoảng chênh lệch giữa thời gian hiện tại và thời gian của lần xử lý trước đó | |
if(currentMillis - previousMillis > interval) { | |
// lưu lại thời gian của vòng lặp vừa mới xử lý | |
previousMillis = currentMillis; | |
// bật tắt đèn ngược với trạng thái hiện tại của đèn | |
if (ledState == LOW) | |
ledState = HIGH; | |
else | |
ledState = LOW; | |
// ghi tín hiệu ra pin 13 | |
digitalWrite(ledPin, ledState); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment