![Adafruit Feather M4 Express Скачать руководство пользователя страница 100](http://html1.mh-extra.com/html/adafruit/feather-m4-express/feather-m4-express_manual_2845857100.webp)
CircuitPython Digital In & Out
The first part of interfacing with hardware is being able to manage digital inputs and outputs. With CircuitPython, it's
super easy!
This example shows how to use both a digital input and output. You can use a switch
input
with pullup resistor (built in)
to control a digital
output
- the built in red LED.
Copy and paste the code into code.py using your favorite editor, and save the file to run the demo.
Note that we made the code a little less "Pythonic" than necessary. The
if/else
block could be replaced with a simple
led.value = not switch.value
but we wanted to make it super clear how to test the inputs. The interpreter will read the
digital input when it evaluates
switch.value
.
For Gemma M0, Trinket M0, Metro M0 Express, Metro M4 Express, ItsyBitsy M0 Express, ItsyBitsy M4 Express, no
changes to the initial example are needed.
For Feather M0 Express and Feather M4 Express, comment out
switch = DigitalInOut(board.D2)
(and/or
switch =
DigitalInOut(board.D7)
depending on what changes you already made), and uncomment
switch =
DigitalInOut(board.D5)
.
For Circuit Playground Express, you'll need to comment out
switch = DigitalInOut(board.D2)
(and/or
switch =
DigitalInOut(board.D5)
depending on what changes you already made), and uncomment
switch =
DigitalInOut(board.D7)
.
# CircuitPython IO demo #1 - General Purpose I/O
import time
import board
from digitalio import DigitalInOut, Direction, Pull
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
# For Gemma M0, Trinket M0, Metro M0 Express, ItsyBitsy M0 Express, Itsy M4 Express
switch = DigitalInOut(board.D2)
# switch = DigitalInOut(board.D5) # For Feather M0 Express, Feather M4 Express
# switch = DigitalInOut(board.D7) # For Circuit Playground Express
switch.direction = Direction.INPUT
switch.pull = Pull.UP
while True:
# We could also do "led.value = not switch.value"!
if switch.value:
led.value = False
else:
led.value = True
time.sleep(0.01) # debounce delay
Note: To "comment out" a line, put a # and a space before it. To "uncomment" a line, remove the # + space
from the beginning of the line.
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
Page 105 of 183
Содержание Feather M4 Express
Страница 1: ...Adafruit Feather M4 Express Created by lady ada Last updated on 2019 03 04 10 41 14 PM UTC...
Страница 5: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 10 of 183...
Страница 58: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 63 of 183...
Страница 164: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 169 of 183...
Страница 168: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 173 of 183...