Easy way to fade the on-board LED?

  • Hi,

    I want to fade the on-board LED from off to full brightness (preferably in a color of choice). Is there an easy way to implement this?

    I want to use a for loop, however I'm not sure how to do that with the HEX value formating for the LED (e.g. from 0x00000 to 0xffffff)


  • @livius

    Thanks! I couldn't figure it out (quite new to python).. Ended up with this:

        def rgb_to_hex(red, green, blue):
            """Return color as #rrggbb for the given color values."""
            return '%02x%02x%02x' % (red, green, blue)
        for i in range(256):
            color = rgb_to_hex(i,i,i)

    This just fades from white to off, removing the '256' fades from off to white.. Probably not the smoothest way to do it, but it works. :)

  • @mahe
    for this puropose you can use HLS color scheme and manipulate brightness
    e.g. use this lib

Log in to reply

Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.