Adafruit_Learning_System_Gu.../CircuitPython_Essentials/CircuitPython_Digital_In_Out.py
2018-03-21 18:04:49 -04:00

24 lines
673 B
Python

# CircuitPython IO demo #1 - General Purpose I/O
import time
from digitalio import DigitalInOut, Direction, Pull
import board
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
switch = DigitalInOut(board.D2) # For Gemma M0, Trinket M0, Metro M0 Express, ItsyBitsy M0 Express
# switch = DigitalInOut(board.D5) # For Feather M0 Express
# switch = DigitalInOut(board.D7) # For Circuit Playground Express
switch.direction = Direction.INPUT
switch.pull = Pull.UP
while True:
# We could also just do "led.value = not switch.value"!
if switch.value:
led.value = False
else:
led.value = True
time.sleep(0.01) # debounce delay