Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

more strange LED behaviour
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

more strange LED behaviour

by Rcayot on Sat Mar 21, 2020 11:37 am

Hi, thanks in advance for your help.

REcently got back to programming mt metro, due to being 'locked up' LOL.

here is my issue, I have a Metro M4 Express and I am trying my hand at driving LEDs with PWM. I have a nice set up based on CircuitPython_PWM.py example.

Code: Select all | TOGGLE FULL SIZE
import time
import board
import pulseio

led1 = pulseio.PWMOut(board.D2, frequency=500, duty_cycle=0)
led2 = pulseio.PWMOut(board.D3, frequency=500, duty_cycle=0)
led3 = pulseio.PWMOut(board.D4, frequency=500, duty_cycle=0)
led4 = pulseio.PWMOut(board.D5, frequency=500, duty_cycle=0)
led5 = pulseio.PWMOut(board.D6, frequency=500, duty_cycle=0)
led6 = pulseio.PWMOut(board.D7, frequency=500, duty_cycle=0)
led7 = pulseio.PWMOut(board.D8, frequency=500, duty_cycle=0)


leds = [led1, led2, led3, led4, led5, led6, led7]
while True:
    for led in leds:

        for i in range(50):
            # PWM LED up and down
            if i < 25:
                led.duty_cycle = int(i * 2 * 65535 / 50)  # Up
            else:
                led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 50)
            time.sleep(0.001)



This runs great, but when LEDs are not being 'used' by the code, they are still lit, but dim. What is happening here? I mean it really isn't all that important, but I am wondering what is going on. I have the LEDs set up on the p[ins with 1000 Ohm resistors.

Thanks,

Roger

Rcayot
 
Posts: 63
Joined: Sat Feb 08, 2020 6:48 pm

Re: more strange LED behaviour

by Rcayot on Sat Mar 21, 2020 11:57 am

okay! never mind. The formula leaves 2% duty cycle, I changed the denominator to 24 and bingo!

Sorry to distract y'all.

Roger

Rcayot
 
Posts: 63
Joined: Sat Feb 08, 2020 6:48 pm

Please be positive and constructive with your questions and comments.