AMP_AVI_Square.png

The

Ray Gun Project

  • HOME

  • LEARN

  • CRAFT

  • SHOP

  • FORUM

  • More

    Use tab to navigate through the menu items.
    0
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    wilsonprints3d
    May 24, 2021

    Adding more color wave code

    in General Discussions

    blue_wave-white_wave
    .PNG
    Download PNG • 21KB

    Hi Andrew, I want to add a few more color pulse options. What is the significance of the 235 (blue) and 175 (white) in the function code? I'm looking to fine tune the potentiometer to allow a few different color options. I copied my WIP code edits below. Also unsure about how to set barrel[p] for different colors.


    def get_mode(mode):

    if mode <= 100:

    barrel.fill((15, 100, 175))

    barrel.show()

    elif mode > 100 and mode <= 200:

    barrel.fill((0, 255, 0))

    barrel.show()

    elif mode > 200 and mode <= 300:

    barrel.fill((255, 0, 0))

    barrel.show()

    elif mode > 300 and mode <= 350: #added

    green_wave() #added

    elif mode > 350 and mode <= 400: #added

    lightblue_wave() #added

    else:

    white_wave()



    #added function

    def green_wave():

    for p in range(bar_pixels):

    GREEN = int(abs(math.sin((p - phase)*3.14 / 18) * 235))+15

    barrel[p] = (0, 0, GREEN)

    barrel.show()

    # time.sleep(0.002)


    #added function

    def lightblue_wave():

    for p in range(bar_pixels):

    LBLUE = int(abs(math.sin((p - phase)*3.14 / 18) * 235))+15

    barrel[p] = (0, 0, LBLUE)

    barrel.show()

    # time.sleep(0.002)



    def blue_wave():

    for p in range(bar_pixels):

    BLUE = int(abs(math.sin((p - phase)*3.14 / 18) * 235))+15

    barrel[p] = (0, 0, BLUE)

    barrel.show()

    # time.sleep(0.002)


    def white_wave():

    for p in range(bar_pixels):

    WHITE = int(abs(math.sin((p - phase)*3.14 / 18) * 175))+15

    barrel[p] = (WHITE, WHITE, WHITE)

    barrel.show()

    # time.sleep(0.002)




    1 answer8 replies
    0
    9 Comments
    A
    Andrew
    May 24, 2021
    Best Answer

    The 235 and 175 are the upper limits of the brightness, the 15 at the end is the lower limit. These numbers can range from 0 - 255, but I didn't like the way it looked when the LED was completely dark at 0 so I set the lower limit to 15. LEDs draw a significant amount of current from the board, so I reduced the maximum brightness to 175 for the white because it uses 3 diodes (which makes it 3 times as bright as the single diode used for blue). For the green wave, you need to move GREEN to the middle: barrel[p] = (0, GREEN, 0). barrel[p] sets the brightness of the Red, Green and Blue diodes (RGB), so barrel[p] = (RED, GREEN, BLUE). That's why you need to put GREEN in the middle for your green wave.


    The light blue wave is a little trickier because light blue is basically BLUE + WHITE. How do you do that with an RGB LED? Well, BLUE = (0, 0, 255) and WHITE = (255, 255, 255), so a little bit of WHITE = (50, 50, 50). We can achieve a light blue by adding a little bit of white to blue. Therefore, LIGHT_BLUE = (50, 50, 255). As long as the values for RED and GREEN are small and the value for BLUE is larger, you'll get a light blue.


    Creating a sin wave a light blue makes things even trickier. Here's my suggestion and then you can play with the values on your own to get the effect you want. def lightblue_wave():

    for p in range(bar_pixels):

    BLUE = int(abs(math.sin((p - phase)*3.14 / 18) * 235))+15

    LIGHT = int(abs(math.sin((p - phase)*3.14 / 18) * 50))

    barrel[p] = (LIGHT, LIGHT, LBLUE)

    barrel.show()

    # time.sleep(0.002)


    Tweak the highlighted values, but don't go beyond 235 for BLUE.

    3
    W
    wilsonprints3d
    May 26, 2021
    Replying to

    @Andrew Thanks for sending the files. I found out when I tried to copy them over I had not enough space from incorrectly disconnecting the feather from my PC which I think corrupted the file partitions.

     

    If anyone happens upon the same problem, or needs to completely reset the feather m0, download the "Mu Editor" and use this guide: https://learn.adafruit.com/welcome-to-circuitpython/troubleshooting#circuitpy-drive-issues-2978456-23

     

    After rebooting with the clean feather, I got your original code to work. Then I got my edits (lights and sound) to work. The speaker still sounds slightly out of tune so I am going to replace that and see if it improves. I appreciate your help!

    Like

    W
    wilsonprints3d
    May 27, 2021
    Replying to

    @Andrew New speaker is in and I redid some of the amp connections. The replacement speaker is noticeably quieter than before, but is not making any bad noises. My custom code is now up and running. Again, thanks for the help troubleshooting and creating this awesome project!

    Like

    A
    Andrew
    May 27, 2021
    Replying to

    @wilsonprints3d Happy to help! Did you get a different speaker or just a replacement? What changes did you make to the amp connections? I've been trying to eliminate the speaker noise for a while!

    Like
    9 comments
    About

    The Ray Gun Project is a prop-making service. We give people the tools and education to make the props they've only dreamed of having.

    • Twitter
    • YouTube
    AMP_AVI_Square.png

    Site by Andrew Lamson 2020. This website is a work-in-progress. All pages, links, images and information are subject to change.