Skip to Content
Node.js物聯網裝置開發
book

Node.js物聯網裝置開發

by Patrick Mulder, Kelsey Breseman
August 2017
Intermediate to advanced
272 pages
5h 32m
Chinese
GoTop Information, Inc.
Content preview from Node.js物聯網裝置開發
34
|
第二章 Arduino 閃爍燈光
然後在 Node.js 環境裡,執行上述腳本程式,便可閃爍 LED
$ node blink_led
若一切正常,便可看到板子上的 LED 開始亮滅循環。現在是個好時機,你可以比較看
看,以 ArduinoC/C++)撰寫的草稿碼、和以 JavaScript 撰寫的程式,有何差異。
在上面的 JavaScript 程式中,取得了
board
物件,經由這個物件可聆聽從硬體傳來的
「事件(event)」。該範例想要閃爍 LED,首先等待、等到板子發出「ready(準備就
緒)」的事件(代表連線正常),該事件發生後,使用
digitalWrite
pinMode.
來改變
板子的功能;從網頁伺服器或網站介面,也能輕鬆地與 JavaScript 物件
board
進行互動
操作(第 9 章和第 10 章將深入介紹)。
微控制器的功能區塊
本章至此,已經看過幾個讓 LED 閃爍的範例,請停下腳步想一想:LED 連接到微控制
器的
腳位
pin
),腳位的作用如同是程式碼和某種電子訊號的介面。腳位可根據功能劃
分成群組,以通訊用的輸入腳位和輸出腳位為例,在微控制器晶片裡,腳位可連接到
時器
timer
),以即時形式操弄訊號。搞清楚腳位的功能並非易事,為了幫助你了解,
最好能準備一張腳位功能圖,隨時查閱(此節最後將會再介紹)。
腳位
微控制器的腳位可分成兩類:
輸入
輸出
,腳位可以「驅使」訊號,送往周邊設備與零
件,或是可以「偵測」來自外界的狀態變化。
從技術上來說,輸入與輸出的差異極大,輸入的功用是捕捉訊號的狀態,輸出則是驅使 ...
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

金融人工智能:用Python实现AI量化交易

金融人工智能:用Python实现AI量化交易

Yves Hilpisch
快学熟用D3

快学熟用D3

Philipp K. Janert

Publisher Resources

ISBN: 9789864764594