Now you can connect with Mu or your favorite serial port software to the CircuitPython runtime, if you hit Control-C a few times you'll get this notice of the build version!
Testing the nRF52840-DK (PCA10056)
Save the following to code.py on the disk drive and re-load it by typing Control-D in the REPL to see LED1 blink!
import time
import board
from digitalio import DigitalInOut, Direction, Pull
led = DigitalInOut(board.P0_13)
led.direction = Direction.OUTPUT
while True:
led.value = False
time.sleep(0.1)
led.value = True
time.sleep(0.1)
You can also read the four buttons and light up corresponding four LEDs on the DK like so:
# CircuitPython IO demo #1 - General Purpose I/O
import time
import board
from digitalio import DigitalInOut, Direction, Pull
led_pins = [board.P0_13, board.P0_14, board.P0_15, board.P0_16]
button_pins = [board.P0_11, board.P0_12, board.P0_24, board.P0_25]
led_outputs = []
for led_pin in led_pins:
led = DigitalInOut(led_pin)
led.direction = Direction.OUTPUT
led_outputs.append(led)
button_inputs = []
for button_pin in button_pins:
button = DigitalInOut(button_pin)
button.direction = Direction.INPUT
button.pull = Pull.UP
button_inputs.append(button)
while True:
for i, button in enumerate(button_inputs):
if not button.value:
print("Button #", i+1, "pressed!")
led_outputs[i].value = button.value
time.sleep(0.01)
Page last edited March 08, 2024
Text editor powered by tinymce.