I've seen this a number of times and can't remember why. Is spin2cpp.exe in that directory? That's mostly a rhetorical question since I see it in my copy of the zip. I'm out of ideas at this point
I'll give this a try on my virtual machine with PropWare installed. It's a bit overkill to install PropWare just for this, but it automates the installation process so it'd be hard to forget something.
Not sure why, but the version of spin2cpp that was included in my Windows release of PropGCC was broken. I'm uploading a new package now with a working copy. In the meantime, simply replace spin2cpp.exe with a copy downloaded directly from the author: https://code.google.com/p/spin2cpp/downloads/detail?name=spin2cpp_v105.zip&can=2&q=
Not sure why, but the version of spin2cpp that was included in my Windows release of PropGCC was broken. I'm uploading a new package now with a working copy. In the meantime, simply replace spin2cpp.exe with a copy downloaded directly from the author: https://code.google.com/p/spin2cpp/downloads/detail?name=spin2cpp_v105.zip&can=2&q=
It could be that spin2cpp isn't included in the version of propgcc that is distributed with SimpleIDE. The trouble is, the version of propgcc that SimpleIDE uses now is rather old. When I get back home I'll update my code to use OpenSpin instead. I'm sure that is included in SimpleIDE. Sorry about the trouble.
Not sure why, but the version of spin2cpp that was included in my Windows release of PropGCC was broken. I'm uploading a new package now with a working copy. In the meantime, simply replace spin2cpp.exe with a copy downloaded directly from the author: https://code.google.com/p/spin2cpp/downloads/detail?name=spin2cpp_v105.zip&can=2&q=
Actually the latest version of spin2cpp is on github, and I recommend using that one:
I guess I should remove the copy from propgcc then. I think we're now using OpenSpin for assembling PASM code now anyway.
Edit: I meant to say maybe we should remove the code for spin2cpp from the propgcc repository and just get it from its official location on github like we do for OpenSpin. I didn't mean we should leave spin2cpp out of the propgcc distributions.
You have to create a command window and run the command line tools. However, maybe instead I should just make a SimpleIDE project for this. I can try making the project tonight but I don't have any WS2812 LEDs with me at the moment so I don't be able to verify it until I get home on Friday night.
I've just attached a Simple Library of this code for use with SimpleIDE to the top post of this thread. I've tested it using an AdaFruit 16 LED ring attached to pin 15 of a PropBOE. It should also work with an ActivityBoard if you connect the ring to pin 15. This is a fairly straight forward translation of JonnyMac's Spin code to C++. In order to use this library I believe all you have to do is copy it into your SimpleIDE workspace under Learn/Simple Libraries/My Libraries. The test program in libws2812.c is the program I used for my Christmas ornament last year. Let me know if you have any problems with this or have any suggestions for improvement.
Works great! So, How would I implement a continuous loop?
All of the smarts is in JonnyMac's PASM code. The ws2812_init function starts a COG running JonnyMac's code and tells it to update the LEDs connected to the specified pin based on the colors in an array of longs that is passed to it. So, in the example, the address of the array "colors" is registered with the PASM COG and the LEDs are automatically updated to match the RGB color values in that array. So, you can get any animation effect you want just by changing the values in that array. The rest of the functions in the library make use of this to achieve various effects. JonnyMac can better describe what these functions do since they match what his Spin functions do. Alternatively, you can just call ws2812_init and then modify the "colors" array yourself to get whatever effect you want. If you want to just light a single LED at a time and loop continuously you can use something like this:
#define MY_COLOR COLOR(255, 0, 0) // red
#define MY_PAUSE 1000 // one second
int i = 0;
while (1) {
colors[i] = COLOR(0, 0, 0);
if (++i >= LED_COUNT)
i = 0;
colors[i] = MY_COLOR;
ws2812_pause(MY_PAUSE);
}
Put this code after the call to ws2812_init and you should get a looping red LED.
I'd like to suggest one simple modification to the ws2812 driver code. Instead of passing the address of an array of RGB longs, why not pass the address of a pointer to an array of RGB longs. That way you can switch arrays by storing a single pointer rather than looping through the entire array changing values. This could allow double buffering. If no one can see a reason not to do this, I think I'll make that change and repost the library code.
That worked!!!! So, how would I add the remaining 6 colors?
You just have to put values in the other elements of the "colors" array. colors[0] is the RGB color of the first LED, colors[1] is the color of the second and so on. You can get any animiation effect you want by change the values in the colors[] array at the right times.
Also, the ws2812_clock_init() and ws2812_pause() functions probably aren't needed as I'm pretty sure there is already some pause or delay function in Simple Libraries. I need to look it up.
I'd like to suggest one simple modification to the ws2812 driver code. Instead of passing the address of an array of RGB longs, why not pass the address of a pointer to an array of RGB longs. That way you can switch arrays by storing a single pointer rather than looping through the entire array changing values. This could allow double buffering. If no one can see a reason not to do this, I think I'll make that change and repost the library code.
Is 255,0,0 suppose to be red? Mine comes up green.
It looks like the ws2811 uses GRB and the ws2812 uses RGB color values. To support this you'll have to swap the first two arguments to the COLOR macro for your LEDs.
OK. I can live with modifying the colors. However, I am confused as to how to add another color. I tried the following with no luck. It just changes the LED from Red to Green.
#include <stdint.h>#include <propeller.h>
#include "ws2812.h"
#define LED_PIN 15
#define LED_COUNT 3
#define MY_COLOR COLOR(0,255, 0) // red
#define MY_COLOR2 COLOR(255,0,0)
#define MY_PAUSE 1000 // one second
int main(void)
{
uint32_t colors[LED_COUNT];
int cog, i;
ws2812_clock_init();
memset(colors, 0, sizeof(colors));
if ((cog = ws2812_init(LED_PIN, colors, LED_COUNT)) < 0)
return 1;
i = 0;
while (1) {
colors[i] = COLOR(0, 0, 0);
if (++i >= LED_COUNT)
i = 0;
colors[i] = MY_COLOR;
colors[i] = MY_COLOR2;
ws2812_pause(MY_PAUSE);
}
cogstop(cog);
return 0;
OK. I can live with modifying the colors. However, I am confused as to how to add another color. I tried the following with no luck. It just changes the LED from Red to Green.
#include <stdint.h>#include <propeller.h>
#include "ws2812.h"
#define LED_PIN 15
#define LED_COUNT 3
#define MY_COLOR COLOR(0,255, 0) // red
#define MY_COLOR2 COLOR(255,0,0)
#define MY_PAUSE 1000 // one second
int main(void)
{
uint32_t colors[LED_COUNT];
int cog, i;
ws2812_clock_init();
memset(colors, 0, sizeof(colors));
if ((cog = ws2812_init(LED_PIN, colors, LED_COUNT)) < 0)
return 1;
i = 0;
while (1) {
colors[i] = COLOR(0, 0, 0);
if (++i >= LED_COUNT)
i = 0;
colors[i] = MY_COLOR;
colors[i] = MY_COLOR2;
ws2812_pause(MY_PAUSE);
}
cogstop(cog);
return 0;
That code just overwrites the first color with the second. If you want to see them both then you'll heed to add a call to ws2812_pause between them.
The intensity of each color is defined by a number 0-255 - an unsigned char in C. (255,0,0) would give full intensity red and no green or blue. (64,64,64) would give a 25% intensity white. (64,64,0) gives you a 25% intensity yellow. (0,0,128) gives you a 50% intensity blue. Play with the R,G and B numbers at http://www.colorpicker.com/ to get a realtime feel on your monitor of how this works.
Like this? If this is correct, then my color scheme is way off!!! I get a light blue for my second color.
#include <stdint.h>#include <propeller.h>
#include "ws2812.h"
#define LED_PIN 15
#define LED_COUNT 3
#define MY_COLOR COLOR(0,255, 0) // red
#define MY_COLOR2 COLOR(255,0, 255)
#define MY_PAUSE 1000 // one second
int main(void)
{
uint32_t colors[LED_COUNT];
int cog, i;
ws2812_clock_init();
memset(colors, 0, sizeof(colors));
if ((cog = ws2812_init(LED_PIN, colors, LED_COUNT)) < 0)
return 1;
i = 0;
while (1) {
colors[i] = COLOR(0, 0, 0);
if (++i >= LED_COUNT)
i = 0;
colors[i] = MY_COLOR;
ws2812_pause(MY_PAUSE);
colors[i] = MY_COLOR2;
ws2812_pause(MY_PAUSE);
}
cogstop(cog);
return 0;
}
You're specifying full intensity of green and full intensity of blue which I suppose gives you a bright blue-green. Try it with the color picker pmrobert posted the link to in message #59. It looks like light blue as you reported.
Comments
I've seen this a number of times and can't remember why. Is spin2cpp.exe in that directory? That's mostly a rhetorical question since I see it in my copy of the zip. I'm out of ideas at this point
I'll give this a try on my virtual machine with PropWare installed. It's a bit overkill to install PropWare just for this, but it automates the installation process so it'd be hard to forget something.
http://forums.parallax.com/showthread.php/157409-How-to-start-with-SimpleIDE
Don't worry... you're not the only one with that question lol
Actually the latest version of spin2cpp is on github, and I recommend using that one:
https://github.com/totalspectrum/spin2cpp/releases/download/v1.91/spin2cpp_v1.91.zip
Thanks,
Eric
Edit: I meant to say maybe we should remove the code for spin2cpp from the propgcc repository and just get it from its official location on github like we do for OpenSpin. I didn't mean we should leave spin2cpp out of the propgcc distributions.
Thanks,
David
Put this code after the call to ws2812_init and you should get a looping red LED.
Also, the ws2812_clock_init() and ws2812_pause() functions probably aren't needed as I'm pretty sure there is already some pause or delay function in Simple Libraries. I need to look it up.
My latest code (auto and single-shot) is available in ObEx (updated 28 SEP 14)
-- http://obex.parallax.com/object/703
Reminder: My code is Spin/PASM -- will need translating for those using C.
EDIT: Any reason my color codes would be wrong? I get red with 255.0,255.