Cloud and Lightning Code for Dimming Expansion

Do you have a question on how to do something.
Ask in here.

Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio
PostPosted: Wed Sep 02, 2015 12:49 pm
cosmith71 wrote:The blue should stay the same. The white should slowly dim with flashes of varying length and intensity, like the videos above.

--Colin


Got it on video if you want to see it but confirmed the white dim out on channel 0 and the blue are the ones flashing on channel 1. Is there something in the bottom part of the code which still has it flash on channel 1?

Code: Select all
    DaylightPWMValue=PWMSlopeHighRes(10,0,20,0,0,30,60,0);
     CheckCloud();
     ReefAngel.PWM.SetChannelRaw(0,DaylightPWMValue);


Only part i changed was this^

Also i just have a general question about this code (10,0,20,0,0,30,60,0) it is (Hour on, minute on,hour off, minute off,starting percentage,max percentage, minutes of ramp up, ?) not sure what this last one is?
Image

Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio
PostPosted: Wed Sep 02, 2015 12:53 pm
Should i just change the whites to channel 1 and the blues to channel 0 and switch them in the void loop?
Image
User avatar
Posts: 1426
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City
PostPosted: Thu Sep 03, 2015 7:11 am
Doh!

Replace the void Strike() section with this.

Code: Select all
void Strike()
    {
      int a=random(1,5);    // Pick a number of consecutive flashes from 1 to 4.
      for (int i=0; i<a; i++)
      {
        // Flash on
        int newdata=4095;
        Wire.beginTransmission(0x40);      // Address of the dimming expansion module
        Wire.write(0x8+(4*0));             // 0x8 is channel 0, 0x12 is channel 1, etc.  I'm using channel 0.
        Wire.write(newdata&0xff);          // Send the data 8 bits at a time.  This sends the LSB
        Wire.write(newdata>>8);            // This sends the MSB
        Wire.endTransmission();
       
        int randy=random(20,80);    // Random number for a delay
        if (randy>71) randy=((randy-70)/2)*100;    // Small chance of a longer delay
        delay(randy);                // Wait from 20 to 69 ms, or 100-400 ms
       
        // Flash off.  Return to baseline.
        newdata=ReefAngel.PWM.GetChannelValueRaw(0);   // Use the channel number you're flashing here
        Wire.beginTransmission(0x40);    // Same as above
        Wire.write(0x8+(4*0));
        Wire.write(newdata&0xff);
        Wire.write(newdata>>8);
        Wire.endTransmission();
       
        delay(random(30,50));                // Wait from 30 to 49 ms
        wdt_reset();    // Reset watchdog timer to avoid re-boots
      }
    }

Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio
PostPosted: Sat Sep 05, 2015 7:10 am
So I had an issue when i tried this yesterday. At first it had dimmed out the blue instead of the white and was flashing in white, so white channel on and flashing white. Then it switched to having the blues on and still flashing white. Instead of tinkering with the code and trying to make sure all the channels are aligned, I am going to switch the channels and reenter code from the first post and see if this fixes the problem.
Image

Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio
PostPosted: Wed Sep 16, 2015 6:08 pm
Just a question about the code.

I don't understand what this does, can you break it down to me like i am 5 years old

Code: Select all
     //#define printdebug // Uncomment this for debug print on Serial Monitor window
    #define forcecloudcalculation // Uncomment this to force the cloud calculation to happen in the boot process.


Thanks for you in advance
Image
User avatar
Posts: 1426
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City
PostPosted: Wed Sep 16, 2015 6:49 pm
Well, #define's main use is to substitute one thing for another. Take this line for example:

Code: Select all
#define ReturnPump        Port1


When you go to compile and upload your code, the compiler goes through and replaces all the instances of ReturnPump with Port1. So this line:

Code: Select all
ReefAngel.Relay.On(ReturnPump);


is seen as this by the compiler:

Code: Select all
ReefAngel.Relay.On(Port1);


This is a common way to give your ports easy to remember names. You don't have to remember what port your return pump is plugged in to, you just tell it ReturnPump and it knows what you're talking about.

THIS IS NOT HOW THIS IS USED HERE!

A second use, which is really just a clever programming trick, is to #define something just so it shows as #defined. They are used as a type of switch That's what these two lines do.

Code: Select all
     //#define printdebug // Uncomment this for debug print on Serial Monitor window
    #define forcecloudcalculation // Uncomment this to force the cloud calculation to happen in the boot process.


So notice that the second part of the #define is missing. We aren't doing a search and replace like in the first usage so we don't need that second part.

Down in the code is this:

Code: Select all
#ifdef forcecloudcalculation
  if (cloudchance==255)
#else
    if (hour()==0 && minute()==0 && second()==1 && cloudchance==255)
#endif


This says "if forecloudcalculation has been defined, then insert 'if(cloudchange==255)' when you compile the code, if it hasn't been defined (else) then insert ' if (hour()==0 && minute()==0 && second()==1 && cloudchance==255) '".

These things exist outside of the compiled code. The compiler goes through and makes these substitutions and insertions before it compiles the code. It's a sneaky way to have the code write itself on the fly depending on what we want.

If we want the #else to be used instead we would just comment out the line like this so that forcedcloudcalculation isn't #defined. Remember that '//' causes everything after it (on the same line) to be ignored.

Code: Select all
    //#define forcecloudcalculation // Uncomment this to force the cloud calculation to happen in the boot process.


Hope this makes sense. It's been a long day. :mrgreen:

--Colin

Posts: 329
Joined: Fri May 17, 2013 1:35 pm
PostPosted: Sun Jan 24, 2016 7:55 am
Well that's a lot of info. I see some have two channels for there lights. I have lights I built with 3 different heat sinks and have each one on its own channel, as in my left heat sink whites and other colors on say channel 1 with the blues on channel 2. Middle heat sink whites and other colors on channel 3 blues channel 4. 3rd heat sink whites and other colors on channel5 blues on channel 6. Not sure if that's the exact set up but that's the general idea how there set up, so I can ramp up each set individually. I'm using analog dimming expansion with DDR drivers. Any special coding I need for clouds and lightning? I know the old dimmer could have a cloud come across the tank from left to right, is this possible with these codes or does it just dim all at the same time?
Image
User avatar
Posts: 1426
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City
PostPosted: Sun Jan 24, 2016 9:10 am
With this code, they all dim at the same time with clouds. As for the lightning, it's just a matter of adding code for the additional channels. I run left and right white channels on mine and they can flash individually or together.

I'm not familiar with DDR drivers. Do you have a link?

--Colin

Posts: 329
Joined: Fri May 17, 2013 1:35 pm
PostPosted: Sun Jan 24, 2016 9:17 am
http://www.rapidled.com/mean-well-eln-6 ... le-driver/

Have you looked at the coding that went directly into the old dimmer?
Image
User avatar
Posts: 1426
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City
PostPosted: Sun Jan 24, 2016 11:04 am
I don't think I've seen it. Do you have a link to it?

I'm familiar with those drivers (ELN). They don't have a fast enough response time for the best lightning effects, but they still work.
PreviousNext

Return to How do I code ...

Who is online

Users browsing this forum: No registered users and 1 guest

cron