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

    Forever changing colors

    Scheduled Pinned Locked Moved LoPy
    rgbled
    4 Posts 2 Posters 1.2k Views 2 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.
    • Z Offline
      zappfinger
      last edited by zappfinger

      Just wanted to share this code. This causes the RGB led to slowly change colors, that will never be the same. Using sine/cosine functions with prime numbers in the argument takes care of this. I should test the variable t for a maximum int and then loop backwards, but ok...

      import pycom
      import math
      
      pycom.heartbeat(False)
      t = 0
      f = 6.28/10000000.
      while 1:
          t+=1
          red = 127 + int(127*math.sin(3*f*t))
          green = 127 + int(127*math.cos(43*f*t))
          blue = 127 + int(127*math.sin(127*f*t))
          pycom.rgbled(red*256*256 + green*256 + blue)
      
      1 Reply Last reply Reply Quote 0
      • Z Offline
        zappfinger
        last edited by

        I'm sorry, the 'Insert code block' does not seem to work for me or I use it wrongly...

        L 1 Reply Last reply Reply Quote 0
        • L Offline
          livius @zappfinger
          last edited by

          @zappfinger said in Forever changing colors:

          I'm sorry, the 'Insert code block' does not seem to work for me or I use it wrongly...

          http://commonmark.org/help/

          think about people first, then computers

          Z 1 Reply Last reply Reply Quote 0
          • Z Offline
            zappfinger @livius
            last edited by

            @livius Thanks!

            1 Reply Last reply Reply Quote 0

            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