blink a single LED on the SAM32

⚙ Hardware Needed


📚 External Libraries Needed


None

📑 Code


blink.py

'''
general blink routine
should work on all boards with an "LED" pin defined in firmware

M.Holliday 2018
'''

import board
import time
import digitalio

# Built in LEDs
led = digitalio.DigitalInOut(board.LED)
led.switch_to_output()

######################### MAIN LOOP ##############################
delay = 2 # make bigger to slow down
i = 0
while True:
  print(i)
  led.value = 1
  time.sleep(delay) 
  led.value = 0
  time.sleep(delay)
  i += 1

Another way to write the while loop (since 🐍 is so cool!)

while True:
  print(i)
  led.value = not led.value
  time.sleep(delay) 
  i += 1