algorithmic modeling for Rhino
Hi, to be honest im not sure with the board section i've chosen for this post, but whatever..
So, i have a question. I'm trying to make my RGB leds fading between its colors with arduino + firefly. So the point is that native firefly fade components are a bit not matching to the task. I only got changing between two colors and it wasn't so smooth with timings etc.
I need to mimic the arduino code logic somehow.
its like:
1. Change Red:255 Green:0 Blue:0 to Red:0 Green:255 Blue:0
2. Delay
3. Change Red:0 Green:255 Blue:0 to Red:0 Green:0 Blue:255
4. Delay
5. Change Red:0 Green:0 Blue:255 to Red:255 Green:0 Blue:0
5. Delay
Changing colors speed is wanted to be controlled as well.
I tried Giulio's Engine component, but it's also not the solution.
I also tried to make some loops in VBscript and C# batteries, but tbh im not skilled in coding, so i had troubles with them.
So i would be happy with any suggestions for the problem!
the arduino code is here:
Tags:
Hi Gi,
This shouldn't be too hard to do with the existing Firefly components (although some of the components in the image below have changed just a little bit so they may not look exactly like what yours looks like). Anyway, you'll probably want to start with a Fader 1-way. I set mine up to go from 0 to 300 over the course of 6 seconds. Then I just wrote a very quick C# component to check the output of the Fader component and whether it met one of three conditions. Here's the code (very simple). Note: you'll need to use the input manager to remove one of the Y input and the output manager to add 2 more outputs (B & C).
if (x <= 100)
{
A = true;
B = false;
C = false;
}
if (x > 100 && x <= 200)
{
A = false;
B = true;
C = false;
}
if (x > 200)
{
A = false;
B = false;
C = true;
}
Now, we know if at any given Fader value if it's in the first phase, second phase, or third phase. I output a boolean value which can also be considered a 0 or 1 if converted to an integer. So, if I multiply those boolean values by 255, then the one that is true will be 255, and the others will always be 0. Now, you should have your color scheme which switches depending on what phase its in. Simply connect that to the Uno Write component (with the Firefly Firmata sketch loaded on your board) and send the color values to the board as PWM values.
Some things I should note... You probably notice the Fader component looks a little different (it's missing the start input and I'm using the GH_Timer). I've decided (for good reason) to abandon the Form Timer I was using in a lot of the Firefly components in favor of the newly re-written GH_Timer component. So, in order to get the Fader component to update in the next version, you have to connect a Timer and turn it on (not that much different). But, it's significantly faster. Part of the reason is that the form timer just wasn't fast enough to get really smooth results... Now, it's blazing fast. I've incorporated this Timer scheme in a lot of the Firefly components and the results are roughly 10x faster. Since, you're only switching values (and not trying to quickly modulate the PWM values) the current version of Firefly should be just fine (just use the Start input to start the Fader component). But, when we release the next version (hopefully very soon), this may change a bit. Anyway, I hope that clarifies it a bit. I've attached a screenshot below. I didn't include the file because I've got a newer version of Firefly that would just crash on you (or not open properly)... but hopefully you can get how to do it.
Wow. thank you for your great contribution! ill try it asap.
sorry for offtop, but is there anything like the release schedule of firefly next builds? Im curios of those features u have noted, like baking the FF code into arduino, kinect component, or any other features. Im asking just because fireflyexperiments.com site is keeping silence, and i have no idea why the community is so inactive? ) your plugin is totally awesome.
Thanks for the kind words. We try to keep an active message board... but it doesn't get the traffic that the Grasshopper site does... so in comparison... it looks inactive. But, the website is also do a total overhaul so hopefully that is in the works too for this summer.
Anyway, it's hard to tell exactly when these things will be released because I'm constantly testing the code and trying to make sure it works properly. Plus new ideas come up and I try to incorporate those too. But each release will have a full readme.txt file which has all the updates for that new release (this one should be big). I'm not sure if the Kinect components will be released in the next build or not... I'm still testing those and I want to make sure it will work relatively seamlessly. Because of the Microsoft SDK, the Kinect component will only be able to be run on Rhino 5 beta (32bit version). You also have to have Windows 7. These are limitations of the Kinect.dll (not mine). It's frustrating, but I'd like to work with the official SDK if at all possible. Anyway, I'll release much more in the next week or so. Thanks again for your interest.
Cheers,
Andy
Two issues.
1. the C# component behaves strange.
Even bare code like this doesnt work fine:
if (x > 100)
{
A = true;
}
The panel from A output shows "null"... Why does it happen?
And second thing is that according to the logic of your deffinition, the LEDs are just switching between colors, and my issue is to make them blend smoothly, fading from color to color.
Thanx in advance!
At first glance... I would say you need to right-click on the x-input and set the type-hint to Double. I'm guessing that's why it doesn't know how to compare the conditional statement. Also, I made a minor mistake in the original code... The second two if statements should be preceded by an else... so it should look like this:
if (x <= 100)
{
A = true;
B = false;
C = false;
}
else if (x > 100 && x <= 200)
{
A = false;
B = true;
C = false;
}
else if (x > 200)
{
A = false;
B = false;
C = true;
}
Secondly... I misunderstood your original intention. From your post, I thought you just wanted to switch between colors at a given time intervals... To blend it, you will need to modify the definition. Let me think about it and see what I can come up with.
-Andy
Thank you very much! The C# script now works. But not in a proper way.
The definition you attached just makes the Red color blink with delay. No switching occurs. Anyways, Thank you.
The code above should at least switch between 3 different colors... or else the circuit is wrong or there is an error somewhere else... because when you start the timer (input) you should see the value 255 switch every 2 seconds. If you've got each input on the Uno Write set to PWM, then you should be sending the 255 PWM value to a different leg on the RGB LED every 2 seconds... This should change the color. If not, there is something else going wrong.
Indeed, my fault. code in the component wasn't updated for some reason.
Still the fade issue is actual, looking forward for your advice.
Hi Gi,
So, I finally had a chance to look at this problem again... and the good news is I found a working solution... the bad news is that I think you wont be able to use it until the next build is released. But hopefully that will be by the end of this week (if we can do the final testing) so I hope that isn't too much of a problem.
So, here's what happened... Basically I needed to know when the fader components started over on their loop cycle. The old components never kept track, but it was easy enough to implement so I added an additional output that keeps track of the number of loop cycles the fader has been through.
So, in the image below, I set the Fader to go from 0-255 over the course of 2 seconds. Every time the loop starts over, then the counter increments by one. If you take the modulo of that counter value (using three as the divisor) then it will return the remainder every time. I can then use this value as the Gate on a Stream Gate component. In the setup below, every time the counter increases by one, the Fader value moves to the next output (this will then control the R, G, or B color values). The only some what annoying part is that the other two outputs on the Stream Gate are left empty... so you need a way to check if they are empty and instead insert a value of 0.0. So, there's one tiny C# component that does this. The code is very basic, but one key thing is that I had to set the type hint on all three inputs to strings. The code is below:
if (string.IsNullOrEmpty(x))A = 0.0;
else A = x;
if (string.IsNullOrEmpty(y))B = 0.0;
else B = y;
if (string.IsNullOrEmpty(z))C = 0.0;
else C = z;
There may be another way to do that without scripting it... but that was the first thing that came to my mind. Once, you do that, then you have all of your RGB values to stream out to the board using the Uno Write. I also added a few utility components to show you what the color would look like on the GH component. If you think this definition is helpful, I could include it in the GH examples of the next build release.
Anyway, sorry that I don't have an immediate solution, but hopefully this will help. And, there may be another way about solving this problem... this was just the first way I came up with.
Cheers,
Andy
Hi, Andy. This is brilliant! Thank you.
Can't wait to see the new build of FF. :)
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by