New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PWMOutputDevice.pulse method #165
Conversation
...which simply calls blink with different default arguments
This may seem a bit trivial, but it means you can just do: from gpiozero import PWMLED
from signal import pause
led = PWMLED(21)
led.pulse()
pause() Argument-order is exactly the same as the existing PWMOutputDevice.blink method. |
Looks good! Could it cope without @waveform80 anything you'd change about this? |
My only concern about this is API bloat (it adds a method to a base class, and there's already a method which accomplishes its goals, albeit without default parameters). I'll defer to @bennuttall's judgement on where to draw the line on such things though. It's also worth noting we already limit which methods appear in the concrete API docs (see the method lists in https://raw.githubusercontent.com/RPi-Distro/python-gpiozero/master/docs/api_output.rst) and hence this method wouldn't automatically appear unless added to the PWMLED list (it will automatically appear in the generic classes docs though as they don't limit which methods appear on the assumption that they're "advanced"). |
Ok I'll think about it. |
Hmmm, maybe it would be worth adding EDIT: And I guess if pulse was added, then https://gist.github.com/bennuttall/aae0ec488216033774ac#file-onboard_leds_pwm-py could be re-written as: from gpiozero import PWMLED
from signal import pause
red = PWMLED(35)
green = PWMLED(47)
def opp():
while True:
yield 1 - red.value
green.source = opp()
red.pulse()
pause() |
To be honest, that could already be written with PWMLED's blink using |
Hmmm, |
I think if we were to add a led.pulse(0, 0, 2, 2) or you'd have to use named parameters: led.pulse(fade_in_time=2, fade_out_time=2) Whereas with led.pulse(2, 2) If you need to pulse but leave on or off for any amount of time, just use I was unsure, but I'm warming to the idea now. |
Fair enough. I guess the other option would be to re-order the arguments of What's the consensus about leaving the method in the base |
Yeah definitely confusing. I'm up for merging with my suggestion thrown in. @waveform80, ok? May as well leave on |
All sounds good to me (i.e. leave it on |
Looks like |
Just for fun*, try this with a buzzer: >>> buzzer = PWMOutputDevice(pin)
>>> buzzer.pulse()
|
Yeah, you'll need to add |
I like |
...which simply calls blink with different default arguments