> For the complete documentation index, see [llms.txt](https://mbyzhang.gitbook.io/loongbian/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mbyzhang.gitbook.io/loongbian/io/adafruit-blinka-library/sample-programs/ban-zai-gpio-shu-chu-you-yuan-feng-ming-qi.md).

# 板载 GPIO 输出：有源蜂鸣器

本样例使用了一个连接到板载 GPIO 接口的有源蜂鸣器模块。Python 程序将会控制该蜂鸣器响一秒。

## 硬件连线

| 模块角标         | 龙芯派接口      | Python 引脚常量名 |
| ------------ | ---------- | ------------ |
| VCC/IN (蜂鸣器) | P13: GPIO2 | GPIO2        |
| GND (蜂鸣器负极)  | P9: GND    |              |

## 代码

```python
import time
import board
import digitalio

buzzer = digitalio.DigitalInOut(board.GPIO2)
buzzer.direction = digitalio.Direction.OUTPUT

buzzer.value = True
time.sleep(1)
buzzer.value = False
```

程序运行后，有源蜂鸣器将会响一秒。
