Ws2811/2812 Programming Help Needed
NWCCTV
Posts: 3,629
Attention ALL programmers, be it Spin or C for SimpleIDE. I am in need of a bit of help here. Our beloved Seahawks are in Phoenix for the Super Bowl and since I am throwing a rather large party I would like to program my WS2811 and WS 2812B's with our team colors, blue and green. I can make them blink blue and green at various speeds but they all blink at the same time. What I would like to do is to have the blue chase the green, the green chase the blue and any other really cool patterns that can be made. I have tried modifying Jonny Mac's awesome driver but I am having no luck. I can not get it to only do blue and green. Any and all help is greatly appreciated.
Comments
Do you have some sort of input device you want to use to change the patterns, colors or brightness?
When I made my "Mood Enhancing LEDs" for my niece, I used a five button input device to select what's being displayed. The project used WS2801 LEDs but I don't think it would be hard to change it to use WS2812 LEDs.
If anyone else wants to help Andy, I hope they speak up. It won't hurt my feelings if someone else jumps in to help.
With JM's code, doing "strip.set" commands with pauses should be fine for what you describe.
Edit: Or you can do "strip.fill"(start_led, end_led, $00_00_00)
There should be no need to modify the driver -- I'm pretty sure it supports any feature you're wanting to use for your animation.
I knocked up a quick demo that may help get you where you want to go.
Do you have my latest driver? (it's included in the archive). It allows you to swap color channels -- I had to set that to true to work with the Adafruit strip I have connected to my PAB.
The effect is similar to my "HypnoRings" code shown in post #1 of this thread. I limited the colors to blue and green. I think it still looks cool with just the two colors.
I added a "BRIGHTNESS" constant to the program to make it easier to adjust the maximum brightness of the LEDs. Jon had the brightness set to 32 ($20). I increased the brightness to 128 ($80). The brightness may be set as high as 255 ($FF). One problem with lower brightness levels is the color depth is reduced, this isn't a problem for the effects Jon added but the effect I added looks better at higher color depths.
As I mentioned, the effect is limited to the blue and green colors. If you wanted to see my effect with the full range of colors, change the value of MIN_COLOR_INDEX and the value of MAX_COLOR_INDEX from (line #196):
to
I have my effect last 20 seconds which is much longer than the duration of either of Jon's effects. I wanted to make sure you could see the colors transition a bit before looping back to the first effect. You'll probably want to either reduce the duration of my effect or increase the duration of Jon's effects.
Here's the line indicating how long to run my effect.
The duration is in units of milliseconds. As the comment warns, durations longer than half the rollover period of the Propeller will cause a problem with the way the method is timed. If you want durations longer than 26.5 seconds, let me know and I can modify the code to use a different time keeping technique.
The effect I added probably will not look good on short strands of LEDs. I think you'd need at least 6 LEDs to get a good effect. I used a strand of 10 LEDs while testing the code.
I hope you try out the this modified version of Jon's demo.
IMO, manipulating memory to produce patterns with LEDs is a great programming exercise. It's a lot of fun to see LEDs do what you tell them to do. It's even more fun when what you think you told them to do turns out to be what you really did tell them to do. Even when the code surprises you with what is displayed on the LEDs it's still fun.
Edit: I know there is a thread about the RS strips but am having trouble locating it. They are the ones that were on clearance last year. May not be WS2811.
I know I had them working with one of the WS2811/2812 code blocks but I just need to figure out which one it was!!!
That needs to somehow be modified for the same thing. Any takers????
It compiles but I haven't tested it.
I just remembered, I forgot to update the comments at the top of the file. It still has the comment stating I was modifying Jon's code. It's still a modified version of Jon's code so I suppose the comment is still true.
Make sure and change the value of "STRIP_LEN" to match number of LEDs in your strip.
In this thread: http://forums.parallax.com/showthread.php/153352-Driver-for-Radio-Shack-tricolor-LED-Strip/page2?highlight=radio+shack+rgb+led#37
JonnyMac has added this:
However, I have no clue as to where in the code it is suppose to be placed. Duane, your code works perfectly and I really like the various patterns but the Blue is Red,
See if this version works.
I didn't change the PASM section, I just changed how blue was defined. This is a very superficial hack.
I hope my section of the code still works. I haven't tested this code on any LEDs. I'm not sure how the changed MIN and MAX color index will affect my color algorithm.
Edit: I had attached the wrong file. See post # 9 for the correct file.
Edit: Did you modify the correct one? The one that is used on the RS strips is the TM1803.
I modified the correct one but I uploaded the wrong one. I'll upload the correct one presently.
Nicely done Duane.
Works great on my new PPDB.
Now I know P15 works. I just need to check 32 more pins.
I'm glad you liked it. I'm very pleased with how well the color merging and blending look. I hope you try out the changes mentioned in post #9 to get the full rainbow effect. If you can arrange your LEDs in a loop of some sort it should look even better since the pixels should be symmetrical around the loop.
Can you describe what you mean by 'chase" a bit more. Is only one LED on at a time?
This will run a single pixel from the start to some end point. If you repeat this with a descending end point you can fill the string with a chase action.
Add this to the loop in the "main" method.
Make sure you try different values when calling the new method (and old).
These LEDs are a fun way to experiment with Spin. Make sure you try to modify the code to make your own patterns.