# \[BASIC] 004 SOUND TONE BUZZER (เสียงดนตรี)

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

คำสั่งที่เกี่ยวข้อง\
lemon.tone() // เป็นการสั่งให้เล่นเสียงดนตรี\
lemon.noTone() // เป็นการสั่งให้หยุดเล่นเสียงดนตรี

```
lemon.tone(1000); // เป็นการสั่งให้เล่นความถี่ 1000 Hz โดยไม่มีการหยุด
lemon.tone(1000,500);  // เป็นการสั่งให้เล่นความถี่ 1000 Hz เป็นเวลา 500 มิลลิวินาที ( 0.5 วินาที ) แล้วหยุดเล่นเสียงนั้น

lemon.noTone();  // เป็นการสั่งให้หยุดเล่นเสียงดนตรี
```

ตัวอย่างการใช้คำสั่ง

```
lemon.tone(1000);  // สั่งให้เล่นความถี่ 1000 Hz
delay(1000);       // รอ 1000 มิลลิวินาที ( 1 วินาที ) (ขณะนี้เสียงยังดังอยู่)
lemon.noTone(500); // สั่งให้หยุดเล่นเสียง
```

เพื่อให้กระชับในการเขียนโปรแกรมบนบอร์ด HONEYLemon ก็สามารถเขียนได้ดังนี้

```
lemon.tone(1000,500);  //เป็นการสั่งให้เล่นความถี่ 1000 Hz เป็นระยะเวลา 500 มิลลิวินาที ( 0.5 วินาที ) แล้วจึงหยุดเล่นเสียงนั้น
```

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

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

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

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

void loop()
{
    /*
        tone(
            1000,   // ความถี่เสียง
            100     // ระยะเวลาที่เล่น (มิลลิวินาที) (option)
        );

        noTone()    // สั่งให้หยุดเล่นเสียงดนตรี
    */
    lemon.tone(1000);   // สั่งให้เล่นเสียงความถี่ 1000 Hz
    delay(100);         // รอ 100 มิลลิวินาที (0.1 วินาที)

    lemon.noTone();     // สั่งให้หยุดเล่นเสียงดนตรี
    delay(100);         // รอ 100 มิลลิวินาที (0.1 วินาที)

    lemon.tone(2000,500);   // สั่งให้เล่นเสียงดนตรีความถี่ 2000 Hz เป็นเวลา 500 มิลลิวินาที ( 0.5 วินาที ) แล้วหยุดเล่นเสียงนั้น
    delay(100);         // รอ 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-004-sound-tone-buzzer.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.
