# 與火災相關的警報零組件

這次一次介紹三種與溫度、火光相關的零組件，熱敏電阻與火燄偵測，熱敏電阻是透過熱的感應，而火燄偵測是感應火光產生的紅外線，各有其用處。另外從這次的介紹可以發現，相同的程式碼可以應用在許多相類似的地方，能深入了解與分辨類比、數位的輸入與輸出，就可以發展出許許多多的用法。

{% embed url="<https://youtu.be/tX2rPsHxqNg>" %}

```python
from gpiozero import MCP3008, LED, Buzzer, Button
from time import sleep


# 使用generator的用法
def convert_temp(gen):
    for value in gen:
        sleep(0.1)
        yield value


adc_sound = MCP3008(0)
led = LED(17)
buzzer = Buzzer(27)
button = Button(21)
# led.on()
# buzzer.on()
# 使用generator的用法
for temp in convert_temp(adc_sound.values):
    # data = temp * 1023
    # print('data: {:.1f}'.format(data))
    # 利用觸發設定值 threshold 觸發警報
    # if data < 510:
    #     led.on()
    #     buzzer.on()
    # else:
    #     led.off()
    #     buzzer.off()
    # 利用數位輸入Digital Out來判斷警報
    if not button.is_active:
        led.on()
        buzzer.on()
    else:
        led.off()
        buzzer.off()

```


---

# 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://s761111.gitbook.io/raspi-sensor/huo-xiang-de-jing-ling-jian.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.
