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)

    Thanks!



  • @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)
            pycom.rgbled(256-int(color,16))
            time.sleep(0.005)
    

    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
    https://github.com/Benhgift/micro-color-clock/blob/master/hls.py



Pycom on Twitter