# \[BASIC] 010 TIME GET TIME (เวลา)

สวัสดีครับ สำหรับหัวข้อบทเรียนพื้นฐานบนบอร์ด HONEYLemon ที่ใช้งานผ่าน arduino library โดยเป็นการใช้งานเกี่ยวกับการอ่านข้อมูล Time ซึ่งจะทำการดึงข้อมูลจากอินเตอร์เน็ตผ่าน WiFi

อ่านข้อมูลเพิ่มเติมสำหรับการเชื่อมต่อ WiFi

{% content-ref url="/pages/-MA5r7zqnmaErAORBQ3y" %}
[\[BASIC\] 007 WiFi SETUP WiFi (ต่อเน็ต)](/blogs/basic/basic-007-wifi-setup-wifi.md)
{% endcontent-ref %}

เมื่อเชื่อมต่อ WiFi ได้แล้วจากบทความข้างต้น ระบบก็จะทำการ sync เวลาให้อัตโนมัติ คราวนี้ก็ทำการดึงข้อมูลมาได้เลย

คำสั่งที่เกี่ยวข้อง

```
        getTime()           // อ่านค่าเวลา ชั่วโมง:นาที:วินาที Hour:Minute:Second (String)
        getTime_Hour()      // อ่านค่าชั่วโมง Hour   0-23  (int)
        getTime_Minute()    // อ่านค่านาที Minute 0-60  (int)
        getTime_Second()    // อ่านค่าวินาที Second 0-60  (int)
```

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

```
String time = lemon.getTime();           // อ่านค่าเวลา ชั่วโมง:นาที:วินาที Hour:Minute:Second (String)
int h = lemon.getTime_Hour();      // อ่านค่าชั่วโมง Hour   0-23  (int)
int m = lemon.getTime_Minute();    // อ่านค่านาที Minute 0-60  (int)
int s = lemon.getTime_Second()    // อ่านค่าวินาที Second 0-60  (int)
```

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

```
/*
    Basic : การเขียนโปรแกรมกับอ่านค่าเวลาจากอินเตอร์เน็ตบนบอร์ดไมโครคอนโทรลเลอร์ HONEYLemon
*/
#include <HONEYLemon.h>

#define WIFI_SSID  "WiFi_Name"      // ตั้งค่าชื่อ WiFi
#define WIFI_PASS  "WiFi_Password"  // ตั้งค่ารหัสผ่าน WiFi

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

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

    // เรียกการใช้งานการตั้งค่า WiFi
    lemon.setupWiFi(WIFI_SSID, WIFI_PASS);
}

void loop()
{
    /*
        getTime()           // อ่านค่าเวลา ชั่วโมง:นาที:วินาที Hour:Minute:Second (String)
        getTime_Hour()      // อ่านค่าชั่วโมง Hour   0-23  (int)
        getTime_Minute()    // อ่านค่านาที Minute 0-60  (int)
        getTime_Second()    // อ่านค่าวินาที Second 0-60  (int)
    */
   
    Serial.println( lemon.getTime() );  // แสดงผลเวลา Hour:Minute:Second

    // Serial.println( lemon.getTime_Hour() );  // แสดงผลชั่วโมง
    //Serial.println( lemon.getTime_Minute() ); // แสดงผลนาที
    //Serial.println( lemon.getTime_Second() ); // แสดงผลวินาที

    delay(1000);    // รอ 1000 มิลลิวินาที (1 วินาที)
}
```


---

# 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-010-time-get-time.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.
