Skip to content

PWMLED doesn't pulse until function returns when called via button press #111

Open
@dwhweb

Description

@dwhweb

Describe the bug
As per the title, if you attempt to pulse a PWMLED via callback associated with a button press, the LED doesn't actually start pulsing until after the function returns. I'd assume this is something to do with how callbacks are handled within the library, as the function works as expected if you call it directly. blink() displays similar behaviour, in that the LED is initially illuminated when the function is called but doesn't actually start blinking until after the function returns.

To Reproduce
Run the following code (obviously GPIO pins need to be changed as appropriate) and press your button.

from picozero import Button, PWMLED
import time

switch = Button(15) 
green_led = PWMLED(13)
green_led.value = 0

def pulse_led():
    print("Pulsing LED...")
    green_led.pulse(fade_in_time=0.25)
    time.sleep(5)
    print("Returning...")

switch.when_pressed = pulse_led

Expected behaviour
I'd expect the LED to start pulsing as soon as the first statement is printed and before the function returns.

System information:

  • OS: Arch Linux (6.4.11-arch2-1)
  • Development environment: Thonny
  • Picozero version: 0.4.2
  • Micropython version: 1.20.0
  • Development board: Raspberry Pi Pico W

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions