Re: Powering External LED Lights
Re: Powering External LED Lights
Re: Powering External LED Lights
Re: Powering External LED Lights
Re: Powering External LED Lights
import time
import board
import pwmio
# Connect the LED to A2 and to GND (You can use A2, A3, A4, A5, A6)
pin = board.A2
led = pwmio.PWMOut(pin, frequency=5000, duty_cycle=0)
# Maximum brightness (0 to 1)
maxBright = 0.5
# Make this value smaller to pulse slower (range 10 to 5000)
step = 1000
dutyMax = int(65000*maxBright)
dutyInc = int(step*maxBright)
while True:
# PWM LED up and down
for i in range(0, dutyMax, dutyInc):
led.duty_cycle = i
time.sleep(0.01)
for i in range(dutyMax, 0, -dutyInc):
led.duty_cycle = i
time.sleep(0.01)
Re: Powering External LED Lights
Re: Powering External LED Lights
import board
import pwmio
pin = board.A2
led = pwmio.PWMOut(pin, frequency=500, duty_cycle=2**16-1)
while True:
pass
Re: Powering External LED Lights
Re: Powering External LED Lights
Re: Powering External LED Lights
Re: Powering External LED Lights
Re: Powering External LED Lights
"""
Demonstrates using the AW9523 GPIO Expander for controlling LEDs
https://www.adafruit.com/product/4886
This lets you attach up to 16 LEDs to your microcontroller.
The code does a few simple ramping lighting effects.
Mark Meier, 02/2022
"""
import time
import busio
import board
import adafruit_aw9523
i2c = busio.I2C(board.SCL, board.SDA)
aw = adafruit_aw9523.AW9523(i2c)
print("Found AW9523")
# Set all pins to outputs and LED (const current) mode
aw.LED_modes = 0xFFFF
aw.directions = 0xFFFF
# Specify the maximum current to use. This determines the brightness.
max_current = 50 # 0 to 255, 0 is off, 255 is max
# The list of pins the LEDs are plugged into. This doesn't have to be sequential.
PINS = [1, 2, 3, 4]
# Set all to the specified current (0 is off)
def set_all(current):
for pin in range(len(PINS)):
aw.set_constant_current(PINS[pin], current)
# Ramp all the LEDs up to max and down again, at the same time
# The value delay is the amount to wait after each step up in current
def ramp_up_down(delay):
for current in range(0, max_current):
for pin in range(len(PINS)):
aw.set_constant_current(PINS[pin], current)
time.sleep(delay)
for current in range(max_current, 0, -1):
for pin in range(len(PINS)):
aw.set_constant_current(PINS[pin], current)
time.sleep(delay)
# Ramp each LED up to max, one after another, leaveing previous ones on
def ramp_each(delay):
for pin in range(len(PINS)):
for current in range(max_current):
aw.set_constant_current(PINS[pin], current)
time.sleep(delay)
# Ramp each LED up to max, turning the previous one off
# before moving to the next LED
def ramp_each_alone(delay, pause_after_on):
for pin in range(len(PINS)):
for current in range(max_current):
aw.set_constant_current(PINS[pin], current)
time.sleep(delay)
time.sleep(pause_after_on)
aw.set_constant_current(PINS[pin], 0) # Turn off the last one
# How much to pause after every change in brightness (in seconds)
current_ramp_delay = 0.01
# Keep looping
while True:
ramp_up_down(0.05)
set_all(0) # Reset all pins to off
ramp_each(current_ramp_delay)
set_all(0) # Reset all pins to off
ramp_each_alone(current_ramp_delay, 0.5)
set_all(0) # Reset all pins to off
Re: Powering External LED Lights