LED Effects with PWM Expansion module

Do you have a question on how to do something.
Ask in here.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

LED Effects with PWM Expansion module

Post by aranax »

Hey guys,
I'm starting a new thread for those of us that have the PWM Expansion module and are utilizing more than 2 drivers to power our LEDs. The current code support that was asked is for the following:

My setup
4 Meanwell P drivers
Driver 0 - Royal Blue
Driver 1 - Regular Blue
Driver 2 - Cool White
Driver 3 - Warm White

PWMSlope:
PWMChannel[LEDPWM0]=PWMSlope(10,30,22,00,0,50,240,PWMChannel[LEDPWM0]);
PWMChannel[LEDPWM1]=PWMSlope(10,00,22,15,0,50,240,PWMChannel[LEDPWM1]);
PWMChannel[LEDPWM2]=PWMSlope(11,0,21,30,0,40,240,PWMChannel[LEDPWM2]);
PWMChannel[LEDPWM3]=PWMSlope(11,30,20,00,0,40,240,PWMChannel[LEDPWM3]);

- Chance of cloud cover/passing clouds would be assessed every even day.
- For clouds all channels would dim with channels 0 and 1 (blues) being the dominant colors. Kinda like moonlights.
- Thunder storms should happen randomly with the beginning resembling cloud cover. No random TStorms when the lights are running "normally". Spikes of channel 2 (Cool white) maybe some warm white as well (what ever is easiest) would be cool along with random number of spikes per cycle. Ie. 1-x spikes of the white channels per random TStorm call.

Naturally, lighting should return to normal after the random effects end.

...getting wave makers to turn on/cycle more violently during TStorms would be a cool next step...

Jeremiah
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Ok, let's work on the passing cloud first.
Can we assign a specific time to start the cloud or you want it to be totally random too?
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

Let's start with random...maybe random within a timeframe if that's easy (16:00 - 22:00)? Otherwise totally random is fine.
Image
NanoTrevor
Posts: 69
Joined: Thu Jun 02, 2011 1:58 pm

Re: LED Effects with PWM Expansion module

Post by NanoTrevor »

lol, perfect, someone else bugging roberto for this. i was wanting this option but figured id bugged roberto enough, tagging along thanks aranax
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Here is what I came up with for calculation the chances of cloud.
Let me know if this works for you.

Code: Select all

    byte cloudchance=0;
    byte cloudduration=0;
    
    // Every day at midnight, we check for chance of cloud happening today
    if (hour()==0 && minute()==0 && second()==0) 
    {
      //Pick a random number between 0 and 99
      cloudchance=random(100); 
      // if picked number is less than 80, we will not have clouds today
      if (cloudchance<80) cloudchance=0;
     // if today is a odd day,  we will not have clouds today. 
      if ((day()%2)!=0) cloudchance=0; 
      // If we have cloud today, pick a random number for the cloud duration. Don't use max duration of more than 255
      if (cloudchance!=0) cloudduration=random(5,50); else cloudduration=0;
    }
Roberto.
NanoTrevor
Posts: 69
Joined: Thu Jun 02, 2011 1:58 pm

Re: LED Effects with PWM Expansion module

Post by NanoTrevor »

hey roberto is there a way to specify a certain channel on the pwm exp mod to work with this code
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

We did not get there yet, but yes there will be.
Right now, we are just working on the percent chance of cloud happening for a particular day.
Roberto.
NanoTrevor
Posts: 69
Joined: Thu Jun 02, 2011 1:58 pm

Re: LED Effects with PWM Expansion module

Post by NanoTrevor »

cool, with this code how will if affect the channels?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

It doesn't do anything yet.
The only thing it is doing right now is checking if there will be a cloud today and how long it will last.
If you read the comments in the code, you will understand what's doing.
I want to make sure this is what the OP had in mind.
Roberto.
NanoTrevor
Posts: 69
Joined: Thu Jun 02, 2011 1:58 pm

Re: LED Effects with PWM Expansion module

Post by NanoTrevor »

ahh, i see said the blind man...
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

looks good to me.

cloudduration=random(5,50)

I'm assuming this means the duration will be random between 5 - 50 seconds, correct?

Jeremiah
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Well, I was thinking of minutes.
If we use seconds, your cloud will never be longer than 5 minutes.
Those parameters can always be changed. If you feel that 50 minute cloud is too long, simply change it to the longest cloud duration you would like to have.
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

even better...I'd prefer minutes. Everything else is in seconds so I assumed this was too. Minutes is fine.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Try this code and let me know if it works for you.

Edit: Attachment was uploaded again after post.
Attachments
Cloud.pde
(5.18 KiB) Downloaded 389 times
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

Thanks Robert. It partially works.

The inverse slopes decrements one unit per minute rather than sloping down to 0 in three minutes. Here is what I did:

Changed this to a test time to see if it triggered. It did NOT so I forced it (below)
// Every day at midnight, we check for chance of cloud happening today
if (hour()==20 && minute()==47 && second()==0)
{

Uncommented code to force cloud cover.
// To test the cloud, you can uncomment this 3 lines below and force a cloud to happen

cloudchance=1;
cloudduration=7;
cloudstart=900;

Verified that cloudcover =1 by adding this draw line. Cloudcover did = 1
ReefAngel.LCD.DrawText(0,255,110,122,cloudchance);

I used the inverse slope function you provided. However, the slope just decremented by 1 every minute.
//is it time for cloud yet?
if (NumMins(hour(),minute())>cloudstart && NumMins(hour(),minute())<(cloudstart+cloudduration))
{
// this will slope down the channel 2 and 3 from the current PWM to 0 within 3minutes.
// then it will stay at 0 for the duration of the cycle
// and finally slope up from 0 to PWM value within 3 minutes
// it is basically an inversed slope
PWMChannel[LEDPWM2]-=PWMSlope(cloudstart/60,cloudstart%60,(cloudstart+cloudduration)/60,(cloudstart+cloudduration)%60,0,PWMChannel[LEDPWM2],3,PWMChannel[LEDPWM2]);
PWMChannel[LEDPWM3]-=PWMSlope(cloudstart/60,cloudstart%60,(cloudstart+cloudduration)/60,(cloudstart+cloudduration)%60,0,PWMChannel[LEDPWM3],3,PWMChannel[LEDPWM3]);

Here is my current slope function. I changed the slope time so that all lights would be on suring my test time.
PWMChannel[LEDPWM0]=PWMSlope(10,30,22,00,0,50,40,PWMChannel[LEDPWM0]);
PWMChannel[LEDPWM1]=PWMSlope(10,00,22,15,0,50,40,PWMChannel[LEDPWM1]);
PWMChannel[LEDPWM2]=PWMSlope(11,0,21,30,0,40,40,PWMChannel[LEDPWM2]);
PWMChannel[LEDPWM3]=PWMSlope(11,30,20,00,0,40,40,PWMChannel[LEDPWM3]);

Thanks again.
Jeremiah
Image
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

hmmm...kinda missed this part..

// pick a random number for when the effect will start. This one is going to be tricky and will require some math.
// the number we want is the number of minutes from midnight that you want to start the effect
// you need to make sure the minimum is after your sunrise effect has at least started.
// in this example case, channel 2 starts at 11:00am and it lasts for 240 minutes
// so we need to start the cloud no earlier than 11:00
// to really see the full effect, no earlier than 3:00pm, which is when the sunrise actually ends.
// for this example, I chose to start the effect no earlier than 3pm and no later than 5pm

I changed the values to reflect my testing window (9:45 PM - my RA is 30 minutes ahead).

cloudstart=random(134,136); //ignore this. I went the wrong direction :(

Here is my PWMSlope:
PWMChannel[LEDPWM0]=PWMSlope(10,30,22,00,0,45,240,PWMChannel[LEDPWM0]);
PWMChannel[LEDPWM1]=PWMSlope(10,00,22,15,0,50,240,PWMChannel[LEDPWM1]);
PWMChannel[LEDPWM2]=PWMSlope(11,0,21,30,0,40,240,PWMChannel[LEDPWM2]);
PWMChannel[LEDPWM3]=PWMSlope(11,30,20,00,0,45,240,PWMChannel[LEDPWM3]);

Here is what happened:

- effect started

channel 0 went to 3
channel 1 went to 6
channel 2 went to 0
channel 3 went to 0

The effect has not ended yet. I'm going to draw cloudduration to the display to see how long it should last and I'll give more info from there. Thanks.

Jeremiah
Last edited by aranax on Wed Jul 20, 2011 9:27 pm, edited 1 time in total.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Hi Jeremiah,

Thanks for testing.
Changing this "if (hour()==20 && minute()==47 && second()==0)" doesn't trigger the cloud. Remember that the day has to be even and there is only 20% chance of happening on that even day.
You can change the percentage though. Simply decrease the number on this line: "if (cloudchance<80) cloudchance=0;"
So, the best thing to force the test is by uncommenting the lines I mentioned. That's why I left them in there.
Regarding the slope, it was by design to slope down in increments of minutes and not seconds. You don't notice it on your regular slope because it is spread into 40 minutes, but it is still in minutes.
We can slope down by seconds, it's just a matter of how much memory you want to allocate for the slope function by seconds versus using something that you already have, which will use far less memory because it is already being used in different parts of your code.
Let me know if you want to use seconds on the reversed slope.
On my tests, it jumped from 40% to 27% to 13% to 0% for every minute that passed. I set the inverse slope to 3 minutes. If you increase the number of minutes, you will achieve a finer decrease. Let's say 10minutes, you would get a decrease of 4% per minute.
Now, let's analyse a real passing short cloud. It actually goes from really bright to very dim in a matter of seconds. On the other hand, for shower type of cloud, you would get a gradual decrease of solar intensity as the clouds get heavier and heavier and they start turning grey and block more and more sun light.
So, it's up to you on how you would like the effect to look like.
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

Thanks Robert. That makes sense. I made a lot of errors in my testing including going the wrong direction with the cloudstart calculation. I'm going to play with this some more to get the hang of it.

One thing I did notice though is that this will call/execute a cloud a cloud effect only once on a given day. Great starting point. Once we get this worked out maybe we can add a random number of times to run the effect (w/ a chance of lightning) when the cloudchance variable is triggered :). hehe..sorry.

Thanks again. This thing rocks.

Jeremiah
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Ok, so I guess I missed a piece of code in the file I uploaded in the previous post.
It doesn't compile.
I went ahead and fixed the code an uploaded it again. Please refer to the post above for the correct file.
Sorry about the mistake.
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

No problem. Thanks Robert. Cloud stuff seems to working fine. I'll see if I can catch a vid of it and post it for people. Can't wait for lightning and stuff :)...

Jeremiah
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Cool.
Now, you mentioned something about having multiple clouds in a day.
I'm confused because you seemed to want to restrict the number of clouds by going just a chance of happening on every even day only to now wanting to have multiple in the same day.
Which way is that you really want to go?
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

Sorry for the miscommunication.

"- Chance of cloud cover/passing clouds would be assessed every even day."

When you said calculate cloud chance every even day I though you meant...
- Every even day we calculate if we will have clouds. This is just a chance calculation.
- I assumed this was just the frequency in which we determine if there is a chance for cloudS
- If the chance is TRUE then we set a random of cloud occurrences.
- during each occurrence there is a random chance of lightning.

Does that make sense?

I'm sure you have a bunch of other things to work on so if adding multiple clouds is a PITA then we can always put that on the back burner. Again, sorry for the miscue.

Jeremiah
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Ok, so here is what we can do:
odd days: no chance
even days: 20% chance (this is configurable)
If we have a cloudy day, we calculate the number of clouds that will happen on this cloudy day (this is also configurable). Note on this one: The duration of clouds will become smaller to accomodate all clouds on a particular day as you increase the number of clouds.
For each cloud, we have a 20% chance of lightining (configurable).
Does that sound good or you have other thoughts?
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

Sounds good.

- Is the duration range still configurable? Meaning a cloud's duration will be randomly set within a configurable range (cloudduration=random(5,50))? It's understood that the more clouds you have, the shorter the clouds must be to accommodate "daytime".

Jeremiah
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Ok, give me some time to work on this now.
I want to make is simpler to use, so I'm going to be moving some stuff around.
Roberto.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Ok, try this one now.
Let me know of it works for you.
The code has a bunch of debug code for me to test different things, but if it works, I'll remove them and create a clean version.
The function takes almost 1.5K of memory space.
There may be ways to decrease a little in the future. I just wanted to get something out to be tested.
Attachments
Cloud.pde
(13.48 KiB) Downloaded 416 times
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

Thanks Robert. It doesn't work for me. I'm assuming this code replaces all the code from the last file, correct? I tried to force a time by uncommenting the three lines defined and on another try I just set the cloud chance timing to my current time. Neither instance resulted in a cloud. What's the best way to test this? thanks.

Jeremiah
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

Yes, the pde is a fully working code.
It won't happen like previously anymore due to the fact you asked for multiple clouds and the time they occur is random now.
But, you can uncomment the #define printdebug and #define forcecloudcalculation, then open the Serial Monitor on arduino and see exactly what's going on.
It will print all the cloud parameters for you and tell you what time the next could is going to happen.
It will also adjust the time too though. I was fast forwarding the time to create the effects in fast forward mode.
But, I think this may be very confusing for you.
I could remove the fast forward if you really want to force a test situation.
So, I think the best thing is to just open Serial Monitor on Arduino and let the controller run its course. When midnight comes, it will print the settings and you will know exactly when the next cloud is going to be.
Roberto.
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: LED Effects with PWM Expansion module

Post by aranax »

I did this:

But, you can uncomment the #define printdebug and #define forcecloudcalculation, then open the Serial Monitor on arduino and see exactly what's going on.

but I'm not getting any output in the serial monitor.

I get this when I run GET /r99 :

HTTP/1.1 200 OK
Server: ReefAngel
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Connection: close
Content-Type: text/xml
Content-Length: 161

<RA><T1>788</T1><T2>986</T2><T3>759</T3><PH>790</PH><R>3</R><RON>0</RON><ROFF>255</ROFF><ATOLOW>0</ATOLOW><ATOHIGH>1</ATOHIGH></RA>

Thanks.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Effects with PWM Expansion module

Post by rimai »

That's the Client app communicating with the controller.
While you are testing things out, you will have to shutdown the listener service.
Roberto.
Post Reply