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 自造手冊:新工業革命實務指南
GPIO
189
範例 18-1
使用 Raspberry Pi 來「閃爍」
# Hello World
import RPi.GPIO as GPIO
import time
pin = 25
#
使用邏輯腳位編號:
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin,GPIO.OUT)
while True:
GPIO.output
(
pin,GPIO.HIGH)
time.sleep(1)
GPIO.output
(
pin,GPIO.LOW)
time.sleep(.5)
您 可 用 nano 文 字 編 輯 器 將 這 段 程 式
碼 建 成 一 個 檔 案( 例 如 語 法:nano
helloworldblink.py)、存檔(Control-O 後
按 下 Enter 或 Return, 再 使 用 Control-X
離開 nano),接著使用超級使用者權限來
執行(因為您無法以一般使用者身分來
存取 GPIO 腳位):
在執行 nano 編輯器前,請確
認是否回到您的家目錄。您無
法在
/sys 目錄下儲存本檔案。
$ sudo python helloworldblink.py
LED 有在閃爍嗎?
由於 while 迴圈實際上沒有檢查任何狀況
(True 就是永遠成立囉),這個程式只要
Raspberry Pi 還有電就會一直執行下去。
您得透過中斷組合鍵 Control-C 來強制停
止它。
按鈕,按鈕
現在試著將一個按鈕接到 GPIO 腳位並
讀 取 其 狀 態。 首 先, 請 用 以
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

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

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

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
Presto实战

Presto实战

Matt Fuller, Manfred Moser, Martin Traverso

Publisher Resources

ISBN: 9789864763238