Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    RGB LED library

    Scheduled Pinned Locked Moved Discussion
    3 Posts 3 Posters 151 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      barryjump
      last edited by

      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.

      1 Reply Last reply Reply Quote 1
      • K Offline
        kjm
        last edited by robert-hh

        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()
        
        1 Reply Last reply Reply Quote 2
        • G Offline
          Gijs
          last edited by

          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.

          1 Reply Last reply Reply Quote 1

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom