Limiting Random Colors on a Standalone BlinkM
I'm trying to get a standalone BlinkM to run through a limited set of random colors. For example, I want only random colors from red to yellow. In some of the built-in scripts, I see that "random" colors (e.g. "old neon") aren't random, but a hard-coded list of specific colors.
I wrote a sketch that first sets the color to red and then writes a script with the following call: { script_speed, {'H', 60 ,0x00,0x00}}. It seems that setting the first param to a low value limits the amount of change related to the last color, rather than the baseline (in this case red).
I abandoned scripts in favor of the making calls to BlinkM_fadeToRGB() in the loop() function. This way I can generate a random number in each loop. The only problem is that this doesn't work for standalone applications. Adding calls to BlinkM_setStartupParams and BlinkM_playScript doesn't make sense, since there is no script being written (although I tried adding them in a desperate attempt to make it work).
So, how would one go about writing a script for standalone applications where, for example, the red value would always be 255 and the green value would be a random number between 0 and 255 each time the script was repeated?
Thanks,
jeff
I wrote a sketch that first sets the color to red and then writes a script with the following call: { script_speed, {'H', 60 ,0x00,0x00}}. It seems that setting the first param to a low value limits the amount of change related to the last color, rather than the baseline (in this case red).
I abandoned scripts in favor of the making calls to BlinkM_fadeToRGB() in the loop() function. This way I can generate a random number in each loop. The only problem is that this doesn't work for standalone applications. Adding calls to BlinkM_setStartupParams and BlinkM_playScript doesn't make sense, since there is no script being written (although I tried adding them in a desperate attempt to make it work).
So, how would one go about writing a script for standalone applications where, for example, the red value would always be 255 and the green value would be a random number between 0 and 255 each time the script was repeated?
Thanks,
jeff
1
person has this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?What's wrong with
{script_speed, { 'n', 255, 0, 0}},
{script_speed, { 'C', 0, 255, 0}}
? -
Inappropriate?Thanks for the reply Fe2o3Fish. The problem with doing that is that I end up with red-->random color-->red-->random color-->red, to infinity and beyond., when I want red-->random color-->random color-->random color, to infinity and beyond. I think the best I'm going to be able to do is:
{script_speed, { 'c', 255, 0, 0}},
{script_speed, { 'C', 0, 255, 0}}, ...40 or so times.
Although not a fully random solution, I should be able to manage with it.
-
Inappropriate?OK, I tested it out and it works pretty well. I decided to stay away from the yellows, since they come out chartreuse, and I had to bump the green value WAY down (0x19, or 25). Since the amount of randomness is related to the previous amount of green, multiple high random values in a row were putting me in the chartreuse range. In case someone is interested, this script fades to full red and runs through a set of 25 random reds through orange-yellows and starts over infinitely (and it runs standalone, powered by 3 AA batteries):
/*************************** BEGIN SCRIPT *********************************/
#include "Wire.h"
#include "BlinkM_funcs.h"
void setup()
{
byte blinkm_addr = 0x10;
byte script_id = 0;
byte script_mode = 1;
byte script_len = 27;
byte script_rep = 0;
byte fade_speed = 1;
byte time_adjust = 0;
byte script_speed = 450; // adjust the amount of time it takes for the script to run
blinkm_script_line script_lines[] = {
{ 1, {'f', 1, 0x00, 0x00}}, // set fade speed speed to slowest
{ script_speed, {'c',0xff, 0x00, 0x00}}, // fade to bright red
{ script_speed, {'C',0x00, 0x19, 0x00}}, // fade to full red/partial-green
{ script_speed, {'C',0x00, 0x19, 0x00}}, // repeat 24 more times...
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
{ script_speed, {'C',0x00, 0x19, 0x00}},
};
BlinkM_beginWithPower();
BlinkM_setAddress( blinkm_addr );
BlinkM_stopScript( blinkm_addr);
BlinkM_setStartupParams(blinkm_addr, script_mode, script_id, script_rep, fade_speed, time_adjust);
BlinkM_writeScript( blinkm_addr, script_id, script_len ,script_rep, script_lines );
BlinkM_playScript( blinkm_addr, script_id,script_rep,0 );
}
void loop()
{
}
/***************************** END SCRIPT *******************************/
I’m Satisfied
-
Inappropriate?Yup, zombieCat, you've come across one of the biggest issues with random colors in BlinkM and a good solution.
In a MaxM, you can specify a "Jump -1" command to have a single command to set the color, then a loop on a single random color command like:
{ 1, {'f', 1, 0x00, 0x00}}, // set fade speed speed to slowest
{ script_speed, {'c',0xff, 0x00, 0x00}}, // fade to bright red
{ script_speed, {'C',0x00, 0x19, 0x00}}, // fade to full red/partial-green
{ 1, {'j', -1, 0, 0}} // jump back one
If this functionality is interesting to you and other original BlinkM users, and you have an AVR-ISP programmer to reflash your BlinkM, I can provide you with a firmware for original BlinkM that has the flow control commands in MaxM. You'd be using an experimental firmware and not officially supported, until I get more time to test it. :)
(also, check out the BlinkMScriptTool Processing app in the BlinkM_Examples.zip for a way to quickly upload/download BlinkM light scripts without needing to program the Arduino each time.) -
Inappropriate?Thanks for the info Tod. Several MaxMs are on my Christmas list :) I've never ventured int AVR-ISP programming, in fact I'm brand new to electronics (but not programming in general). I'll try my hand at reflashing after finishing some other projects.
I'm having a lot of fun with these things, and I'm dreaming up all kinds of applications for them. Your support is outstanding as well.
As it stands, my solution works quite well, because I actually like the hit of red at the beginning of each script--it's spaced out enough to be just right. Thanks again (and also to Fe2o3Fish for pointing out that I needed to pull my head out of my 4th point of contact and think about it in a different way).
As a side note, do you have any suggestions for a good diffuser for the MaxMs (since they're too big for glue sticks)? I was thinking of a ping pong ball but would love to hear if you've used something particularly successfully.
z
I’m Exceptionally satisfied
-
Inappropriate?Hmmm, diffusers for MaxM. A ping-pong ball might be too small, I'll have to give it a try. Because the MaxM Blasters are so bright compared to BlinkM, I usually end up just pointing the MaxMs up at the ceiling or wall to create a color wash. I've also had good luck with a thin sheet of white foam arched over the Blaster.
-
Inappropriate?Very good, thanks. I'll be using my MaxMs behind some frames on the wall, so they may actually work quite well with the natural color wash.
-
Inappropriate?Tod,
I have an STK-500, think that'll re-flash an original BlinkM? I'm all into experimental firmware -- I write it all the time! {hint, hint} :-)
Also, I have used ping-pong balls with my BlinkM's. Problem is that the LED in the BlinkM has a clear lense. Sure would like to have a diffused lense. I've been thinking about using a Dremel tool to rough up the LED to see if that'll diffuse the light enough for a more consisent illumination of my ping-pong balls. Maybe a little foam might help. Hmmm...
BTW, just on the off chance, does anyone know if solid ping-pong balls (not made from two halves) are even obtainable, much less ones without printing on them? The printing can be removed but I'd sure like a solid, one piece ball. Thanks!
-Rusty- -
Inappropriate?Rusty,
You might actually want to try the glue stick trick. Just grab a stick for a glue gun, cut about a half-inch section off of it, throw it in a vice and drill the end using a 3/8" drill bit, to a depth of about 1/8 of an inch. You'll have just enough glue left around the edge to slip over the LED. I think a 7/16 bit would actually be a bit better (didn't have one). With the 3/8, I ended up heating the bottom of the drilled-out stick with a lighter held under it--about 8 inches below for a second or two--to soften it just enough to make it a bit more plieable. It diffuses the light quite well, and it's as cheap as horse feet.
Loading Profile...




EMPLOYEE