# 按鈕模組

## 按鈕模組 <a href="#toc124882502" id="toc124882502"></a>

**專案說明**

使用「Raspberry Pi Pico W」連接「按鈕模組」, 讀取按鈕模組的數值變化。此**按鈕模組**包含於「洞洞五教學材料包」內。

### **按鈕模組電路圖**

* Raspberry Pi Pico W
* Raspberry Pi Pico W 擴充板
* 按鈕模組

**按鈕模組**是**數位訊號**輸入， 可以接「D0\~ D28」的Raspberry Pi Pico擴充板訊號端上。 本範例連接到「D7」

以下介紹兩款按鈕模組的接線圖，一款是上面有金色字體寫著「**digital Push Button Module V2.0**」，另一款模組沒有。

**有**寫「**digital Push Button Module V2.0**」的按鈕模組接線圖

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FhnoAJz3KXdInZyc36lVE%2F0.png?alt=media)

**沒有**寫「**digital Push Button Module V2.0**」的按鈕模組接線圖

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FMYjNWiZdVvVQprGOR9r7%2F1.png?alt=media)

### **BlocklyDuino 程式 (Button)**

兩款的程式都是相同的，請見下圖。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FLImlmrDMm77Ba1Tl2HQ7%2F2.png?alt=media)

### **Arduino 程式(Button.ino)如下**

```
void setup()
{
pinMode(7, INPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println(digitalRead(7));
delay(500);
}
```

### **程式執行結果:**

兩款模組操作上有差異，**有**寫「**digital Push Button Module V2.0**」的按鈕模組接線圖，是**按鈕壓下為1，放開為0。**

而**沒有**寫「**digital Push Button Module V2.0**」的按鈕模組接線圖，是**按鈕壓下為0，放開為1。**

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FrqBbcUx8jfF6PSby3wfw%2F3.png?alt=media)
