The Planted Tank Forum - Reply to Topic
Planted Tank Forums
Your Tanks Image Hosting *Tank Tracker * Plant Profiles Fish Profiles Planted Tank Guide Photo Gallery Articles

Go Back   The Planted Tank Forum > Specific Aspects of a Planted Tank > DIY > Calling all DIY LED "Junkies" - Your opinions wanted!

Thread: Calling all DIY LED "Junkies" - Your opinions wanted! Reply to Thread
Title:
  
Message:
Post Icons
You may choose an icon for your message from the following list:
 

Register Now

In order to be able to post messages on the The Planted Tank Forum forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in

Human Verification

In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.



Additional Options
Miscellaneous Options

Topic Review (Newest First)
01-18-2013 03:18 PM
O2surplus
Quote:
Originally Posted by skanderson View Post
put the new file you put up in there and still get the same error messages. clearly im screwing something up but i have no idea what.
I sent you a PM. Have you tried uploading some simpler code, like the "blink" sketch? I'm just trying a little remote trouble shooting here.
01-17-2013 10:40 AM
skanderson put the new file you put up in there and still get the same error messages. clearly im screwing something up but i have no idea what.
01-17-2013 03:55 AM
O2surplus
Quote:
Originally Posted by skanderson View Post
according to my library i have ds1037RTC as a CPP file in my ardino library. is that the wrong one? if it is the proper one why isnt it working?
Just toss in the one that I posted and see what happens.
01-16-2013 11:18 PM
skanderson according to my library i have ds1037RTC as a CPP file in my ardino library. is that the wrong one? if it is the proper one why isnt it working?
01-16-2013 11:02 PM
O2surplus
Quote:
Originally Posted by skanderson View Post
ok i pasted it into my ardino oo23. when i try to verify or upload i get the following message/*
Code:
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use. 
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule.  
//  Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3;       // LED PWM arduino pin for channel one.

int twoLed = 5;       // LED PWM arduino pin for channel two 

int threeLed = 6;     // LED PWM arduino pin for channel three

int fourLed = 9;      // LED PWM arduino pin for channel four

int fiveLed = 10;     // LED PWM arduino pin for channel five

int sixLed = 11;      // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h> 
// written by  mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0;         // counter that resets at midnight. Don't change this.



int oneStartMins = 540;     // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420;      // minute to start channel 2. Change this to the number of minutes past midnight you want to start                         

int threeStartMins =540;    // minute to start channel 3. Change this to the number of minutes past midnight you want to start 

int fourStartMins =420;     // minute to start channel 4. Change this to the number of minutes past midnight you want to start 

int fiveStartMins =420;     // minute to start channel 5. Change this to the number of minutes past midnight you want to start 

int sixStartMins =420;      // minute to start channel 6. Change this to the number of minutes past midnight you want to start 


int onePhotoPeriod = 720;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day                           

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180;      // duration of the fade on and off for sunrise and sunset. Change
                            
//    this to alter how long the fade lasts.

int oneMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255;           // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 255;         // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

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

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins,    // current time in minutes
            
int ledPin,  // pin for this channel of LEDs
            
int start,   // start time for this channel of LEDs
            
int period,  // photoperiod for this channel of LEDs
            
int fade,    // fade duration for this channel of LEDs
            
int ledMax   // max value for this channel
            
)  {
  
if (mins <= start || mins <= mins > start + period)  {
    
analogWrite(ledPin, 0);
  
}// This is when the led's are off, thus ledVal =0
  
if (mins > start && mins <= start + fade)  {
    
analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  
}// This is sunrise. Leds slowly brighten to full intensity
    
if (mins > start + fade && mins <= start + period - fade)  {
   
analogWrite(ledPin, ledMax);
  
}//This is when the led's are at maximum intensity
    
if (mins > start + period - fade && mins <= start + period)  {
    
analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));
  
}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

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

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{
  
return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{
  
return ( (val/16*10) + (val%16) );

}



// 1) Sets the date and time on the ds1307

// 2) Starts the clock

// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




void setDateDs1307(byte second, // 0-59 
                   
byte minute, // 0-59
                   
byte hour, // 1-23
                   
byte dayOfWeek, // 1-7
              
byte dayOfMonth, // 1-28/29/30/31
                   
byte month, // 1-12
                   
byte year) // 0-99

{
   
Wire.beginTransmission(DS1307_I2C_ADDRESS);
   
Wire.send(0);
   
Wire.send(decToBcd(second));
   
Wire.send(decToBcd(minute));
   
Wire.send(decToBcd(hour));
   Wire.send(decToBcd(dayOfWeek));
   
Wire.send(decToBcd(dayOfMonth));
   
Wire.send(decToBcd(month));
   
Wire.send(decToBcd(year));
   
Wire.endTransmission();
     
                             

}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,
          
byte *minute,
          
byte *hour,
          
byte *dayOfWeek,
          
byte *dayOfMonth,
          
byte *month,
          
byte *year)

{
  
Wire.beginTransmission(DS1307_I2C_ADDRESS);
  
Wire.send(0);
  
Wire.endTransmission();

  

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  
*second     = bcdToDec(Wire.receive() & 0x7f);
  
*minute     = bcdToDec(Wire.receive());
  
*hour       = bcdToDec(Wire.receive() & 0x3f);
  
*dayOfWeek  = bcdToDec(Wire.receive());
  
*dayOfMonth = bcdToDec(Wire.receive());
  
*month      = bcdToDec(Wire.receive());
  
*year  = bcdToDec(Wire.receive());

}



void setup()  { 
    


// init I2C  
  
Serial.begin(9600);
  
Wire.begin();
} 
// these functions only occur once.



/***** Main Loop ***********/

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

void loop() { 

 
 
  

// get time from RTC and put in hrs and mins variables
  
getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  
minCounter = rtcHrs * 60 + rtcMins;
 
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  
Serial.print("      "); // some space for a more happy life
  
Serial.print(RTC.get(DS1307_MTH,false));//read month
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_DATE,false));//read date
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_YR,false)); //read year 
  
Serial.println();


//set LED values
  
setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);
  
setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);
  
setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);
  
setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);
 
setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);
   
setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);
 
// Get ready for next iteration of loop
  
delay(1000);
all that is in red under a message that says RTC was not declared in this scope . what am i doing wrong? thanks again for the help.
You probably don't have the needed "DS1307" Library installed in your arduino's library folder. Here's the library- just place the unzipped folder into your "library" folder and try again.
01-16-2013 09:55 PM
skanderson ok i pasted it into my ardino oo23. when i try to verify or upload i get the following message/*
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use.
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule.
// Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3; // LED PWM arduino pin for channel one.

int twoLed = 5; // LED PWM arduino pin for channel two

int threeLed = 6; // LED PWM arduino pin for channel three

int fourLed = 9; // LED PWM arduino pin for channel four

int fiveLed = 10; // LED PWM arduino pin for channel five

int sixLed = 11; // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h>
// written by mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0; // counter that resets at midnight. Don't change this.



int oneStartMins = 540; // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420; // minute to start channel 2. Change this to the number of minutes past midnight you want to start

int threeStartMins =540; // minute to start channel 3. Change this to the number of minutes past midnight you want to start

int fourStartMins =420; // minute to start channel 4. Change this to the number of minutes past midnight you want to start

int fiveStartMins =420; // minute to start channel 5. Change this to the number of minutes past midnight you want to start

int sixStartMins =420; // minute to start channel 6. Change this to the number of minutes past midnight you want to start


int onePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180; // duration of the fade on and off for sunrise and sunset. Change

// this to alter how long the fade lasts.

int oneMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int threeMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

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

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins, // current time in minutes

int ledPin, // pin for this channel of LEDs

int start, // start time for this channel of LEDs

int period, // photoperiod for this channel of LEDs

int fade, // fade duration for this channel of LEDs

int ledMax // max value for this channel

) {

if (mins <= start || mins <= mins > start + period) {

analogWrite(ledPin, 0);

}// This is when the led's are off, thus ledVal =0

if (mins > start && mins <= start + fade) {

analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));

}// This is sunrise. Leds slowly brighten to full intensity

if (mins > start + fade && mins <= start + period - fade) {

analogWrite(ledPin, ledMax);

}//This is when the led's are at maximum intensity

if (mins > start + period - fade && mins <= start + period) {

analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));

}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

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

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{

return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{

return ( (val/16*10) + (val%16) );

}



// 1) Sets the date and time on the ds1307

// 2) Starts the clock

// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




void setDateDs1307(byte second, // 0-59

byte minute, // 0-59

byte hour, // 1-23

byte dayOfWeek, // 1-7

byte dayOfMonth, // 1-28/29/30/31

byte month, // 1-12

byte year) // 0-99

{

Wire.beginTransmission(DS1307_I2C_ADDRESS);

Wire.send(0);

Wire.send(decToBcd(second));

Wire.send(decToBcd(minute));

Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));

Wire.send(decToBcd(dayOfMonth));

Wire.send(decToBcd(month));

Wire.send(decToBcd(year));

Wire.endTransmission();



}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,

byte *minute,

byte *hour,

byte *dayOfWeek,

byte *dayOfMonth,

byte *month,

byte *year)

{

Wire.beginTransmission(DS1307_I2C_ADDRESS);

Wire.send(0);

Wire.endTransmission();



Wire.requestFrom(DS1307_I2C_ADDRESS, 7);


*second = bcdToDec(Wire.receive() & 0x7f);

*minute = bcdToDec(Wire.receive());

*hour = bcdToDec(Wire.receive() & 0x3f);

*dayOfWeek = bcdToDec(Wire.receive());

*dayOfMonth = bcdToDec(Wire.receive());

*month = bcdToDec(Wire.receive());

*year = bcdToDec(Wire.receive());

}



void setup() {



// init I2C

Serial.begin(9600);

Wire.begin();
}
// these functions only occur once.



/***** Main Loop ***********/

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

void loop() {





// get time from RTC and put in hrs and mins variables

getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);

minCounter = rtcHrs * 60 + rtcMins;

Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true

Serial.print(":");

Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)

Serial.print(":");

Serial.print(RTC.get(DS1307_SEC,false));//read seconds

Serial.print(" "); // some space for a more happy life

Serial.print(RTC.get(DS1307_MTH,false));//read month

Serial.print("/");

Serial.print(RTC.get(DS1307_DATE,false));//read date

Serial.print("/");

Serial.print(RTC.get(DS1307_YR,false)); //read year

Serial.println();


//set LED values

setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);

setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);

setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);

setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);

setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);

setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);

// Get ready for next iteration of loop

delay(1000);

all that is in red under a message that says RTC was not declared in this scope . what am i doing wrong? thanks again for the help.
12-14-2012 06:27 PM
mistergreen I just noticed something in the code, for those that had a hard time with the code.

This is a release note from the arduino app last year.

Quote:
* The WProgram.h file, which provides declarations for the Arduino API,
has been renamed to Arduino.h. To create a library that will work in
both Arduino 0022 and Arduino 1.0, you can use an #ifdef that checks
for the ARDUINO constant, which was 22 and is now 100. For example:

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
12-14-2012 06:07 PM
mistergreen
Quote:
Originally Posted by skanderson View Post
ok now to sound really dumb, how do i get this into the ardino. do i type it in or can i import it?
Copy and paste but make sure to download and place libraries in the right place. When you try to compile, the arduino app will yell at you.
12-14-2012 05:42 PM
O2surplus
Quote:
Originally Posted by skanderson View Post
ok now to sound really dumb, how do i get this into the ardino. do i type it in or can i import it?

Copy&Paste my friend!

Highlight all code that I posted, Right Click "COPY" and then Paste it into the Arduino IDE.
Click the button that says VERIFY to make sure that it compiles properly, and then either "Save" the Sketch or "Upload" it to the Arduino.
12-14-2012 05:04 PM
jarvitron
Quote:
Originally Posted by skanderson View Post
ok now to sound really dumb, how do i get this into the ardino. do i type it in or can i import it?
There's no such thing as a dumb question, but that's a dumb question for an aquarium forum.
12-14-2012 04:49 PM
skanderson ok now to sound really dumb, how do i get this into the ardino. do i type it in or can i import it?
12-12-2012 11:41 PM
O2surplus
Quote:
Originally Posted by skanderson View Post
ok been too busy with other projects to mess with the coding and get it working. is there a way that i could download someone elses dimming and timing code to get it up and working. all im looking for is a 1 to2 hour ramp up and down with a 12 hour on/off cycle for all 6 channels. and i will definately be interested in the new build you are putting together. thanks again in advance, steve


Here's some code that will get you up and running. Just adjust the variables to your liking and let-her-rip.

Code:
/*
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use. 
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule.  
//  Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3;       // LED PWM arduino pin for channel one.

int twoLed = 5;       // LED PWM arduino pin for channel two 

int threeLed = 6;     // LED PWM arduino pin for channel three

int fourLed = 9;      // LED PWM arduino pin for channel four

int fiveLed = 10;     // LED PWM arduino pin for channel five

int sixLed = 11;      // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h> 
// written by  mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0;         // counter that resets at midnight. Don't change this.



int oneStartMins = 540;     // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420;      // minute to start channel 2. Change this to the number of minutes past midnight you want to start                         

int threeStartMins =540;    // minute to start channel 3. Change this to the number of minutes past midnight you want to start 

int fourStartMins =420;     // minute to start channel 4. Change this to the number of minutes past midnight you want to start 

int fiveStartMins =420;     // minute to start channel 5. Change this to the number of minutes past midnight you want to start 

int sixStartMins =420;      // minute to start channel 6. Change this to the number of minutes past midnight you want to start 


int onePhotoPeriod = 720;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day                           

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180;      // duration of the fade on and off for sunrise and sunset. Change
                            
//    this to alter how long the fade lasts.

int oneMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255;           // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 255;         // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

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

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins,    // current time in minutes
            
int ledPin,  // pin for this channel of LEDs
            
int start,   // start time for this channel of LEDs
            
int period,  // photoperiod for this channel of LEDs
            
int fade,    // fade duration for this channel of LEDs
            
int ledMax   // max value for this channel
            
)  {
  
if (mins <= start || mins <= mins > start + period)  {
    
analogWrite(ledPin, 0);
  
}// This is when the led's are off, thus ledVal =0
  
if (mins > start && mins <= start + fade)  {
    
analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  
}// This is sunrise. Leds slowly brighten to full intensity
    
if (mins > start + fade && mins <= start + period - fade)  {
   
analogWrite(ledPin, ledMax);
  
}//This is when the led's are at maximum intensity
    
if (mins > start + period - fade && mins <= start + period)  {
    
analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));
  
}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

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

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{
  
return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{
  
return ( (val/16*10) + (val%16) );

}



// 1) Sets the date and time on the ds1307

// 2) Starts the clock

// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




void setDateDs1307(byte second, // 0-59 
                   
byte minute, // 0-59
                   
byte hour, // 1-23
                   
byte dayOfWeek, // 1-7
              
byte dayOfMonth, // 1-28/29/30/31
                   
byte month, // 1-12
                   
byte year) // 0-99

{
   
Wire.beginTransmission(DS1307_I2C_ADDRESS);
   
Wire.send(0);
   
Wire.send(decToBcd(second));
   
Wire.send(decToBcd(minute));
   
Wire.send(decToBcd(hour));
   Wire.send(decToBcd(dayOfWeek));
   
Wire.send(decToBcd(dayOfMonth));
   
Wire.send(decToBcd(month));
   
Wire.send(decToBcd(year));
   
Wire.endTransmission();
     
                             

}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,
          
byte *minute,
          
byte *hour,
          
byte *dayOfWeek,
          
byte *dayOfMonth,
          
byte *month,
          
byte *year)

{
  
Wire.beginTransmission(DS1307_I2C_ADDRESS);
  
Wire.send(0);
  
Wire.endTransmission();

  

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  
*second     = bcdToDec(Wire.receive() & 0x7f);
  
*minute     = bcdToDec(Wire.receive());
  
*hour       = bcdToDec(Wire.receive() & 0x3f);
  
*dayOfWeek  = bcdToDec(Wire.receive());
  
*dayOfMonth = bcdToDec(Wire.receive());
  
*month      = bcdToDec(Wire.receive());
  
*year  = bcdToDec(Wire.receive());

}



void setup()  { 
    


// init I2C  
  
Serial.begin(9600);
  
Wire.begin();
} 
// these functions only occur once.



/***** Main Loop ***********/

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

void loop() { 

 
 
  

// get time from RTC and put in hrs and mins variables
  
getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  
minCounter = rtcHrs * 60 + rtcMins;
 
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  
Serial.print("      "); // some space for a more happy life
  
Serial.print(RTC.get(DS1307_MTH,false));//read month
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_DATE,false));//read date
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_YR,false)); //read year 
  
Serial.println();


//set LED values
  
setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);
  
setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);
  
setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);
  
setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);
 
setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);
   
setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);
 
// Get ready for next iteration of loop
  
delay(1000);

}
12-12-2012 11:33 PM
skanderson ok been too busy with other projects to mess with the coding and get it working. is there a way that i could download someone elses dimming and timing code to get it up and working. all im looking for is a 1 to2 hour ramp up and down with a 12 hour on/off cycle for all 6 channels. and i will definately be interested in the new build you are putting together. thanks again in advance, steve
12-06-2012 03:22 PM
O2surplus
Quote:
Originally Posted by biogenetic40379 View Post
How much does it cost to make something like this to control full spectrum lighting. Looking at making one for my bio cube (reef w/ led retro fit coming soon)
By rough estimate - A controller with 4 MeanWell LDD drivers = $100. The Lm3409 drivers would drive the price up another $30.

I'm in the process of building the first one right now. When I'm done testing it and make any needed changes, I'll post the revised build files along with the Bill of Materials ( with links for purchasing) and the Software.
12-06-2012 05:03 AM
biogenetic40379 How much does it cost to make something like this to control full spectrum lighting. Looking at making one for my bio cube (reef w/ led retro fit coming soon)
This thread has more than 15 replies. Click here to review the whole thread.

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 03:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright Planted Tank LLC 2012