Skip to main content

LEDs

Stemi shield has an onboard LED connected to pin IO12 and can control external LEDs connected to GPIO pins.

LED

Library

For simple usage DigitalIO can be used to turn it on or off, but if you want more precise control you can use PWM.

Example

digitalio_example.py
import board
from stemi.digitalio import DigitalInOut, Direction

led = DigitalInOut(board.IO12)
led.direction = Direction.OUTPUT

led.value = 0 # off
time.sleep(1)

led.value = 1 # on
time.sleep(1)
pwm_example.py
import board
from stemi.pwmio import PWMOut

led = PWMOut(board.IO12, duty_cycle=2 ** 16 - 1, frequency=50)

led.duty_cycle = 0 # 0% duty cycle (off)
time.sleep(1)

led.duty_cycle = int((2 ** 16 - 1) / 2) # 50% duty cycle (half on)
time.sleep(1)

led.duty_cycle = 2 ** 16 - 1 # 100% duty cycle (on)
time.sleep(1)