# \[BASIC] 006 MICRO SD CARD (ไฟล์บนไมโครเอสดีการ์ด)

สวัสดีครับ สำหรับหัวข้อบทเรียนพื้นฐานบนบอร์ด HONEYLemon ที่ใช้งานผ่าน arduino library โดยเป็นการใช้งานเกี่ยวกับการจัดการไฟล์บน Micro-SD Card ซึ่งผู้พัฒนาได้พัฒนา library ให้สามารถใช้งานได้ง่ายมาก และรองรับบนบอร์ดเลยไม่ต้องซื้ออุปกรณ์ต่อเพิ่ม

คำสั่งที่เกี่ยวข้องการการอ่านเขียนไฟล์บน Micro-SD Card\
lemon.createFile() // เป็นฟังก์ชั่นสำหรับการสร้างไฟล์\
lemon.writeFile() // เป็นฟังก์ชั่นสำหรับการเขียนไฟล์\
lemon.writeFileln() // เป็นฟังก์ชั้นสำหรับการเขียนไฟล์และเว้นบรรทัด\
lemon.readFile() // เป็นฟังก์ชั่นสำหรับการอ่านไฟล์\
lemon.renameFile() // เป็นฟังก์ชั่นสำหรับการเปลี่ยนชื่อไฟล์\
lemon.removeFile() // เป็นฟังก์ชั่นสำหรับการลบไฟล์

```
//Micro SD Card Function
        
createFile(__Filename__)                // สำหรับสร้างไฟล์บนไมโครเอสดีการ์ด
        
writeFile(__Filename__, __Text__)       // สำหรับเขียนตัวอักษรลงบนไฟล์ในไมโครเอสดีการ์ด
writeFileln(__Filename__, __Text__)     // สำหรับเขียนตัวอักษรลงบนไฟล์ในไมโครเอสดีการ์ด พร้อมเว้นบรรทัด

readFile(__Filename__)                  // สำหรับอ่านไฟล์ โดยจะคืนค่าเป็นสตริง (String)
removeFile(__Filename__)                // สำหรับลบไฟล์
        
renameFile(old___Filename__,new___Filename__)   // สำหรับเปลี่ยนชื่อไฟล์
```

ตัวอย่างการใช้งาน

```
...
   lemon.createFile("text.txt");                        // สร้างไฟล์ชื่อว่า text.txt
   lemon.writeFile("text.txt","Hello HONEYLemon\n");    // เขียนข้อความว่า "Hello HONEYLemon" ลงในไฟล์ text.txt
   
   Serial.println( lemon.readFile("text.txt") );        // อ่านไฟล์ text.txt (String) แล้วแสดงผล

   lemon.renameFile("text.txt","text.txt.backup");      // เปลี่ยนชื่อไฟล์ text.txt เป็น text.txt.backup
   lemon.removeFile("text.txt.backup");                 // ลบไฟล์ text.txt.backup
...
```

**ตัวอย่าง source code**

```
/*
    Basic : การเขียนโปรแกรมกับการใช้งานไมโครเอสดีการ์ดบนบอร์ดไมโครคอนโทรลเลอร์ HONEYLemon
*/
#include <HONEYLemon.h>

void setup()
{
    lemon.begin();          // เรียกใช้งานฟังก์ชั่นเริ่มต้นของบอร์ด HONEYLemon

    Serial.begin(115200);   // เรียกใช้งาน Serial
    lemon.debug(Serial);    // ขอดู debug ของบอร์ด HONEYLemon ผ่าน Serial

    /*
        Micro SD Card Function
        
        createFile(__Filename__)                // สำหรับสร้างไฟล์บนไมโครเอสดีการ์ด
        
        writeFile(__Filename__, __Text__)       // สำหรับเขียนตัวอักษรลงบนไฟล์ในไมโครเอสดีการ์ด
        writeFileln(__Filename__, __Text__)     // สำหรับเขียนตัวอักษรลงบนไฟล์ในไมโครเอสดีการ์ด พร้อมเว้นบรรทัด
        
        readFile(__Filename__)                  // สำหรับอ่านไฟล์ โดยจะคืนค่าเป็นสตริง (String)
        removeFile(__Filename__)                // สำหรับลบไฟล์
        
        renameFile(old___Filename__,new___Filename__)   // สำหรับเปลี่ยนชื่อไฟล์
    */

   lemon.createFile("text.txt");                        // สร้างไฟล์ชื่อว่า text.txt
   lemon.writeFile("text.txt","Hello HONEYLemon\n");    // เขียนข้อความว่า "Hello HONEYLemon" ลงในไฟล์ text.txt
   
   Serial.println( lemon.readFile("text.txt") );        // อ่านไฟล์ text.txt (String) แล้วแสดงผล

   lemon.renameFile("text.txt","text.txt.backup");      // เปลี่ยนชื่อไฟล์ text.txt เป็น text.txt.backup
   lemon.removeFile("text.txt.backup");                 // ลบไฟล์ text.txt.backup
}

void loop()
{
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lemon.honey.co.th/blogs/basic/basic-006-micro-sd-card.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
