Skip to Content
自造手冊:新工業革命實務指南
book

自造手冊:新工業革命實務指南

by Paolo Aliverti, Andrea Maietta
March 2017
Intermediate to advanced
232 pages
4h 44m
Chinese
GoTop Information, Inc.
Content preview from 自造手冊:新工業革命實務指南
第 16 章 Arduino
150
與真實世界互動
我們要介紹第一個簡單的指令,使作品
可以動起來。
指定腳位的動作
Arduino 開發板上有好幾個腳位,
圖 16-8
中可以看到,腳位 0-13 以淺色顯示。這
些腳位都是數位式驅動,只能執行 0 和 1
的程式。若它們是水龍頭,則只能完全
打開或完全關閉。
圖 16-8
Arduino 的數位腳位
製作 Arduino 原 型 平台的好處之一,是
可以改變數位腳位的動作,並決定要將
它們用作輸入或輸出。要放入 setup 函式
的指令很簡單。舉例來說,將腳位 13 設
為輸出的程式為:
pinMode(13, OUTPUT);
將腳位 7 設為輸入的程式碼 :
pinMode(7, INPUT);
基本上,pinMode 指令可以接受兩個參
數:第一個參數決定哪個腳位要執行開
關,第二個參數則決定腳位執行的方式
為輸入(INPUT)或輸出(OUTPUT)。
若您將某一個腳位設為輸入,卻從該腳
位輸出,或是相反過來,都有可能會造
成 Arduino 或連接的電子裝置故障。
該將開關打開嗎?
若您已將一腳位設為輸出,您可以利用
digitalWrite 指令「開」或「關」。這個功
能接受兩個參數:第一個參數是希望執
行的腳位,第二個參數則是您想執行的
動作(例如:電流是否從該腳位輸出)。
如前所述,數位腳位只能用來開或關—
全開或全關,不能開一半或關一半。
將腳位 13「打開」的程式碼:
digitalWrite(13, HIGH);
將腳位 13「關閉」的程式碼:
digitalWrite(13
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

網頁互動式資料視覺化:使用D3

網頁互動式資料視覺化:使用D3

Scott Murray
優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone

Publisher Resources

ISBN: 9789864763238