Created
April 2, 2019 14:44
-
-
Save vixtory09678/7ef693a8149de21d1ac5aebf9a281c33 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
/* | |
การสร้าง function มีด้วยกันอยู่ 3 ส่วนใหญ่ ๆ ดังนี้ | |
(ชนิดตัวแปรที่ต้อง return กลับ) (ชื่อ Function) (ตัวแปรที่ต้องการป้อนเข้าให้กับ Function) | |
float getAreaCircle (float radius) | |
*/ | |
//ทีนี้เขียนใหม่ให้มันถูกกับภาษา c++ จะได้ | |
float getAreaCircle(float radius){ | |
// เขียนคำสั่งของ Function ไว้ในนี้ | |
float area = 2*3.1413*(radius * radius); | |
return area; | |
} | |
// สร้าง function แบบไม่มี return ค่า เราจะใช้คำสั่ง void ดังนี้ | |
void openLed(int time){ | |
// เขียนคำสั่งของ Function ไว้ในนี้ | |
digitalWrite(13,HIGH); | |
delay( time ); // เอาตัวแปรที่รับเข้ามาใช้ในการหน่วงเวลาได้ | |
digitalWrite(13,LOW); | |
// function แบบไม่มี return ค่า จะไม่มีคำสั่ง return ตอนจบ function | |
} | |
// สร้าง function ธรรมดา ที่ไม่มีทั้ง return ค่าหรือรับค่าใด ๆ เข้ามาก็ได้ | |
void closeLedMain(){ | |
digitalWrite(5,LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment