RGB LED library



  • Has anyone built a library for elegantly interacting with the RGB Led on the FiPy for example with predefined functions?

    If not, maybe we can do this collectively for the benefit of everyone and publish here?

    I'm realizing the limitations of my Python skills, so I'll show an example of what I'm trying to do.

    For example: A simple LED "heartbeat" mode. Note, someone more skilled could probably reduce this to 4-5 lines.

    def bootlights():
        print("Booting up... ")
        loops = 10
        while loops > 0:
            pycom.rgbled(0x020002)
            time.sleep(.05)
            pycom.rgbled(0x030003)
            time.sleep(.05)
            pycom.rgbled(0x040004)
            time.sleep(.05)
            pycom.rgbled(0x050005)
            time.sleep(.05)
            pycom.rgbled(0x060006)
            time.sleep(.05)
            pycom.rgbled(0x070007)
            time.sleep(.05)
            pycom.rgbled(0x080008)
            time.sleep(.05)
            pycom.rgbled(0x090009)
            time.sleep(.05)
            pycom.rgbled(0x080008)
            time.sleep(.05)
            pycom.rgbled(0x070007)
            time.sleep(.05)
            pycom.rgbled(0x060006)
            time.sleep(.05)
            pycom.rgbled(0x050005)
            time.sleep(.05)
            pycom.rgbled(0x040004)
            time.sleep(.05)
            pycom.rgbled(0x030003)
            time.sleep(.05)
            print(loops)
            loops -= 1
    

    Maybe some other universally usable RGB modes: Data sent pattern, Data received pattern, Searching for signal pattern, battery low pattern, etc.



  • I think its a very interesting idea! Ive suggested a feature to the FW team to make pycom.rgbled() return the current value of the led if no color value is given, such that you can reset the color after each function call. Now to make this a good library, I would suggest a nonblocking function that handles the setting of the led, and creates a timer of sort to reset the led at the end, to not keep the main program busy.



  • I got so excited the first time I managed to download new boot.py code into the gpy over lte I did a little happy dance.

    import pycom, time; pycom.heartbeat(False)
    red=0x7f0000; green=0x007f00; orange=0xff5100; blue=0x00007f; off=0x000000; white=0x7f7f7f; magenta=0x7f007f; cyan=0x007f7f; yellow=0x7f5100
    def _ledspkl():
        t=.07; lookup=[red, orange, yellow, green, cyan, blue, magenta, white]             # .7x.07=.49s(colours)+.49(whites)=1s
        for k, v in enumerate(lookup): pycom.rgbled(v); time.sleep(t); pycom.rgbled(white); time.sleep(t)
    
    _ledspkl()
    

Log in to reply
 

Pycom on Twitter