Created
May 8, 2016 19:13
-
-
Save jackrobotics/973bc9664acdec38a8052f14b1a8eb84 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
int ledState = LOW; | |
/* กำหนดตัวแปร ledState สำหรับเก็บสถานะเริ่มต้นของ led */ | |
unsigned long previousMillis = 0; | |
/* กำหนดตัวแปน previousMillis สำหรับเก็บข้อมูลเวลาก่อนหน้า */ | |
long interval = 1000; | |
/* กำหนดตัวแปร interval เพื่อใช้ในการปรับเปลี่ยนเวลาในการเปลียน ledState */ | |
void setup() { | |
pinMode(13, OUTPUT); | |
/*ฟังก์ชั่น pinMode(13,OUTPUT); คือการกำหนดโหมดของการทำงานของขานั้นๆ เช่นคำสั่งนี้จะทำให้ขา 13 มีสถานะคือการ output นั้นคือสามารถกำหนดให้มีไฟออกจากไมโครคอนโทรเลอร์ได้ว่าจะให้ออก 0V หรือ 5V ตาม logic ที่เรากำหนดในโปรแกรม หรือพูดให้เข้าใจง่ายๆ คือ สั่งหรือติดหรือดับนั้นเอง*/ | |
} | |
void loop() { | |
unsigned long currentMillis = millis(); | |
/*กำหนดตัวแปร currentMillis เพื่อเก็บข้อมูลเวลาปัจจุบัน */ | |
if (currentMillis - previousMillis >= interval) { | |
/* if เป็นคำสั่งตรวจสอบ และในที่นี้คือจะตรวจสอบว่าเวลาปัจจุบัน - เวลาอดีต ผลจะทำให้ได้ค่าส่วนต่างเวลาที่เคยกระทำก่อนหน้า */ | |
previousMillis = currentMillis; | |
/* ทำการเก็บค่าเวลาปัจจุบัน เพื่อใช้เป็นเวลาอดีตในการตรวจสอบ if ครั้งต่อไป */ | |
if (ledState == LOW) { | |
/* ตอนนี้สถานะ led ไหน ถ้า LOW อยู่ให้ สั่งสลับกันคือ HIGH*/ | |
ledState = HIGH; | |
} else { | |
/* ถ้าไม่ใช่ LOW ให้สั่งสลับกันคือ HIGH*/ | |
ledState = LOW; | |
} | |
digitalWrite(13, ledState); | |
/* ทำการ update สถานะปัจจุบันให้แสดงผล */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment