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)
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.