# 微動開關模組

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-LoyhZ7TGT0i8ZxuGcbY%2F-LoyhbVQabn9bNQxtlPC%2Flinkit7697_microswitch_00.png?generation=1568715213791781\&alt=media)

## LinkIt 7697 專案說明

使用「LinkIt 7697 NANO Breakout」連接「微動開關模組」,每0.2秒讀取微動開關模組按下和放開。

此**微動開關模組**包含於「[**洞洞么教學材料包**](https://www.robotkingdom.com.tw/product/rk-education-kit-001/) 」內。

### LinkIt 7697 電路圖

* [LinkIt 7697](https://www.robotkingdom.com.tw/product/linkit-7697/)
* LinkIt 7697 NANO Breakout
* 微動開關模組

**微動開關模組**是**數位訊號**輸入， 可以接「D0 \~ D13」的 LinkIt 7697 NANO Breakout訊號端上，「A0 \~ A3」在程式代表「14 \~ 17」。 本範例連接到「**D5**」。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-LoyhZ7TGT0i8ZxuGcbY%2F-LoyhbVUIvU-KabGwfs8%2Flinkit7697_microswitch_01.png?generation=1568715211155720\&alt=media)

### BlocklyDuino 積木畫布

每0.2秒鐘會讀取微動開關模組的開啟或關閉一次， 並顯示在序列埠監控視窗上。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-LoyhZ7TGT0i8ZxuGcbY%2F-LoyhbVXAqfq3Fb8zUWd%2Flinkit7697_microswitch_02.png?generation=1568715211125790\&alt=media)

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-LoyhZ7TGT0i8ZxuGcbY%2F-LoyhbV_kUWPmz48FEkH%2Flinkit7697_microswitch_03.png?generation=1568715211232266\&alt=media)

### Arduino 程式

```c
void setup()
{
  pinMode(5, INPUT);
  Serial.begin(9600);
}

void loop()
{
  Serial.println(digitalRead(5));
  delay(200);
}
```

## micro:bit 專案說明

使用「micro:bit搭配科易KEYES micro:bit 感測器擴充板 V2」連接「微動開關模組」，讀取微動開關模組按下或放開的狀態。

此**微動開關模組**包含於「[**洞洞么教學材料包**](https://www.robotkingdom.com.tw/product/rk-education-kit-001/)」內。

### micro:bit電路圖

* [BBC micro:bit 微控制板  ](https://www.robotkingdom.com.tw/product/bbc-microbit-1/)
* [科易KEYES micro:bit 感測器擴充板 V2  ](https://www.robotkingdom.com.tw/product/keyes-microbit-sensor-breakout-v2/)
* 微動開關模組

**微動開關模組**是**數位訊號**輸入，可以接「3、4、5、6、7、9、10、11」的 micro:bit訊號端上，建議使用的是5跟11腳位，因為3、4、6、7、9、10腳位有使用到LED控制腳位所以當顯示LED時會不穩定。 本範例連接到「P5」。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-M-NFAtslwbo7DvWmrex%2F-M-NFhdC4bOqeeRl-x51%2F01.JPG?alt=media\&token=56f1cd93-7912-46f4-98d9-82b248d7f108)

### Microsoft MakeCode積木畫布

每1秒鐘會讀取微動開關模組狀態一次，並可透過micro:bit顯示指示燈看到微動開關模組的狀態。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-M-NFAtslwbo7DvWmrex%2F-M-NGEzpgnwBtqkwIPT7%2F02.jpg?alt=media\&token=37e290e9-6074-4c76-919c-6f488f557e78)

### JavaScript 程式

```javascript
basic.forever(function () {
    basic.showNumber(pins.digitalReadPin(DigitalPin.P5))
    basic.pause(1000)
})

```

## Raspberry Pi Pico 專案說明

使用「Raspberry Pi Pico」連接「微動開關模組」, 每0.2秒讀取微動開關模組按下和放開。此**微動開關模組**包含於「[洞洞么教學材料包](https://robotkingdom.com.tw/product/rk-education-kit-001/)」內。

### 微動開關模組電路圖

* [Raspberry Pi Pico](https://robotkingdom.com.tw/product/raspberry-pi-pico/)[  ](https://www.robotkingdom.com.tw/product/bbc-microbit-1/)
* [Raspberry Pi Pico擴充板](https://robotkingdom.com.tw/product/pipico-education-kit-001/)[  ](https://www.robotkingdom.com.tw/product/keyes-microbit-sensor-breakout-v2/)
* 微動開關模組

> **微動開關模組**是**數位訊號**輸出， 可以接「D0 \~ D28」的Raspberry Pi Pico擴充板訊號端上。 本範例連接到「D7」。

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FUAaQm6Dmf6GZ21IHEW9d%2Fimage.png?alt=media&#x26;token=ef1a45e7-51b9-4c80-b7f4-71658e63bffa" alt=""><figcaption></figcaption></figure>

### Arduino IDE程式

> 每0.2秒讀取微動開關模組按下和放開。

Arduino 程式(Micro\_Switch.ino)如下:

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

&#x20;

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

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FOxk7gAA9FSOSHQ4L2GQO%2Fimage.png?alt=media&#x26;token=01aee219-2eb4-46b0-9e43-2260e7715f5d" alt=""><figcaption></figcaption></figure>
