Page 1 of 1
What is making my LED's go yellow?
Posted: Wed Nov 16, 2016 4:53 am
by gregsvo
Here's my code:
[code]
import time, machine, neopixel, math
number_of_leds = 60
np = neopixel.NeoPixel(machine.Pin(5), number_of_leds)
def main():
while True:
fade_in_out(red_val=256, green_val=256, blue_val=256) # white
def fade_in_out(red_val, green_val, blue_val):
for i in range(256):
r = math.ceil((i/256)*red_val)
g = math.ceil((i/256)*green_val)
b = math.ceil((i/256)*blue_val)
for pixel_num in range(0, number_of_leds):
np[pixel_num] = (r, g, b)
np.write()[/code]
The animation starts at well, but ends fading into a yellow. Here is a (sped up) gif of what it looks like:
http://imgur.com/a/t1CWX
Any help/code suggestions would be greatly appreciated! Thanks.
edit: Sorry for the lack of code editing... couldn't get it to work right.
Re: What is making my LED's go yellow?
Posted: Wed Nov 16, 2016 12:22 pm
by torwag
What makes me suspicious, is the 256.
You have 8 bits per color which is a number between 0 and 255, in total 256 values.
That is the maximum brightness level you can get is 255,255,255 and not 256,256,256
Maybe that solves already the problem
Re: What is making my LED's go yellow?
Posted: Wed Nov 16, 2016 1:08 pm
by Neil
I don't think that is the problem as whilst you are right about the 256 and 255 issue, his actual code will work out to 255 anyway as the maximum of range(256) is 255 and math.ceil(255/256*256) is 255.
I would guess that it is some sort of timing issue with the data transfer.
Re: What is making my LED's go yellow?
Posted: Wed Nov 16, 2016 1:44 pm
by gregsvo
Neil wrote:...I would guess that it is some sort of timing issue with the data transfer.
Can you speak more about this? I'm not sure where to start. The LED's go yellow on different codes as well, for example:
Code: Select all
import time, machine, neopixel
number_of_leds = 60
np = neopixel.NeoPixel(machine.Pin(5), number_of_leds)
def main():
while True:
strobe(red_val=0xff, green_val=0xff, blue_val=0xff, strobe_count=10, flash_delay=50, end_pause=1000)
def strobe(red_val, green_val, blue_val, strobe_count, flash_delay, end_pause):
for _ in range(0, strobe_count):
set_all(red_val=red_val, green_val=green_val, blue_val=blue_val)
show_strip()
time.sleep_ms(flash_delay)
set_all(0, 0, 0)
show_strip()
time.sleep_ms(flash_delay)
time.sleep_ms(end_pause)
def show_strip():
np.write()
def set_pixel(pixel_num, red_val, green_val, blue_val):
np[pixel_num] = (red_val, green_val, blue_val)
def set_all(red_val, green_val, blue_val):
for i in range(0, number_of_leds):
set_pixel(pixel_num=i, red_val=red_val, green_val=green_val, blue_val=blue_val)
show_strip()
Re: What is making my LED's go yellow?
Posted: Thu Nov 17, 2016 9:04 am
by pythoncoder
I've not followed this in detail but there has been recent work on Github to address Neopixel timing issues. Have you updated the firmware?
Re: What is making my LED's go yellow?
Posted: Thu Nov 17, 2016 9:41 am
by platforma
Re: What is making my LED's go yellow?
Posted: Fri Nov 18, 2016 5:08 pm
by gregsvo
I haven't updated to 1.8.6 yet, but will give it a try today, and report back. Thanks!
Re: What is making my LED's go yellow?
Posted: Mon Nov 21, 2016 3:17 pm
by gregsvo
THANK YOU Pythoncoder and Platforma!
The update to 1.8.6 fixed the issue.