8000 pyb module: pyb.Led · Issue #125 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content
pyb module: pyb.Led #125
Closed
Closed
@Neon22

Description

@Neon22

I'd like to start a discussion about what the pyb.Led construct should support and how it will work. (If this discussion works then maybe we could similarly examine the other pyb functions we want to expose. starting simple)

What do we want the pyb.Led structure to look like in the pyb module?

We currently have it mapped to (up to 4) on-board Leds only.
Like this:

led = pyb.Led(led_id) # led_id is mapped to onboard pin (set to output)
led.on()  # sets pin high
led.off() # sets pin low

However there's no real difference here compared to setting a pin as an output.
E.g. something like the arbitrarily named Digital_output

led = pyb.Digital_output(pin) # sets pin to output (
led.on()  # sets pin high
led.off() # sets pin low

There is no real reason for a return value but possibly a get method could find out the last set state.

But an LED can have other properties e.g. brightness which could be set by PWM.

E.g.

led = pyb.Led(pin, value=0) # default arg
led.set_value(intensity)    # a pwm percentage expressed 0-255
led.set_percent(intensity)  # expressed as percent 0-100

or a more complex construct for RGB LEDs
E.g.

led = pyb.RGBLed(rpin, gpin, bpin) # define three pins as output
led.set_rgb(r,g,b) # as byte values 0-255
led.set_ihs(i,h,s) # set value in different colour space
led.set_bias(r_gamma, g_gamma, b_gamma) # so the color space can be calibrated
led.get_RGB() # return RGB values last set
led.get_IHS() # for IHS aspect

These methods are really using PWM.
On the micropython board - hardware PWM is readiily available on most pins. But there are a limited number of PWM generators.
Nevertheless its useful to be able to set the pwm frequency or use software PWM
E.g.

led = pyb.Led(pin, pwm_freq=1000)

Could be a way to do it.
Or separately define a PWM object (perhaps start a new thread about this)
E.g.

led_pwm = pyb.PWM(frequency, HARDWARE) # or SOFTWARE (using a background interrupt routine)
led = pyb.Led(pin, pwm=led_pwm)

What do people think is the right thing to do for pyb.Led class ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    rfcRequest for Comment

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0