Sunrise and sunset effect with your PWM Expansion Module

Would you like to help?
Share your walkthrough tutorial with others

Posts: 12282
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Tue Aug 23, 2011 8:35 am
Let's start by assuming the following:
  • You are using the most current development libraries. If you are unsure or don't have the most updated, you can simply follow the instructions in this thread to update/convert: viewtopic.php?f=8&t=2
  • You already have everything connected and tested. If not, please read through the manual: http://www.reefangel.com/files/Reef%20A ... 20v1.0.pdf
  • You have modified the file ReefAngel_Features.h to include the PWM Expansion code into the libraries. If not, the file is located at "Documents\Arduino\libraries\ReefAngel_Features". Open it in notepad and make sure that you have "#define PWMExpansionRelay" and that it does not have "//" in front of it.

Now that we have everything we need to get the effect coded, lets start.
The first thing we are going to to is declare some variables and labels we are going to be used within our code. This piece of code goes above setup() function.
Code: Select all
//**********************************************************************************//Start of PWM Expansion Code Header

// This is just how we are going to reference the PWM expansion ports within the code.
// You can change the labels if you would like, just as long as they are changed all throughout the code too.
#define LEDPWM0 0
#define LEDPWM1 1
#define LEDPWM2 2
#define LEDPWM3 3
#define LEDPWM4 4
#define LEDPWM5 5

// Initial values to all 6 channels at startup. They will always be 0.
byte PWMChannel[]={
  0,0,0,0,0,0};

//End of PWM Expansion Code Header

//**********************************************************************************


Then, we can now calculate the slope for the effect. This piece of code goes inside loop() function.
Code: Select all
//**********************************************************************************//Start of PWM Expansion Code for Slope
    PWMChannel[LEDPWM0]=PWMSlope(15,0,21,30,15,45,90,PWMChannel[LEDPWM0]);
    PWMChannel[LEDPWM1]=PWMSlope(15,0,21,30,15,45,90,PWMChannel[LEDPWM1]);
    PWMChannel[LEDPWM2]=PWMSlope(15,0,21,30,15,45,90,PWMChannel[LEDPWM2]);
    PWMChannel[LEDPWM3]=PWMSlope(15,0,21,30,15,45,90,PWMChannel[LEDPWM3]);
    PWMChannel[LEDPWM4]=PWMSlope(15,0,21,30,15,45,90,PWMChannel[LEDPWM4]);
    PWMChannel[LEDPWM5]=PWMSlope(15,0,21,30,15,45,90,PWMChannel[LEDPWM5]);
   
    // In the example above, we are starting the slope at 3:00pm with 15% and going up to 45% within 90 minutes, which would be 4:30pm.
    // Then it would stay at 45% from 4:30 to 90 minutes prior to 9:30pm, which would be 8:00pm.
    // Then from 8:00pm, it would start sloping down from 45% all the way back to 15% within 90 minutes, which would be 9:30pm.

    for (int a=0;a<6;a++)
    {
      ReefAngel.PWMExpansion(a,int(2.55*PWMChannel[a]));
    }
   
//End of PWM Expansion Code for Slope
//**********************************************************************************


That's it.
The attached PDE file has the complete code you can use for your reference.
Attachments
PWMExpansionSlope.pde
(2.56 KiB) Downloaded 223 times
Roberto.

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests

cron