Reef Pico LED intefacing, 3 watt LED's and RTC

huzzzar!

i've managed to fix the majority of the code, infact most of that code above needed re-writing/ tweeking.

im just testing it a bit more then i'll start looking into intergrating an LCD and buttons.

once ive got the fade to work correctly (im sure its just some of my syntax) i'll post the latest code.

edited later:

Well here we are at the moment, i've managed to write the correct code which fades leds in and out at user defined times.

The next stage is to incroperate an LCD and buttons, so i can write code for a menu system that enables the user to set the Maximum led intensity values (fadeMaxWhite and fadeMaxBlue) and then write code that enables the user to define what time they would like the various lights to come on and off at.

Then from there id like to rig a Moonlight, with a 1 watt led maybe. or possibly play with LED matrix's for random weather patterns maybe.

//Marine Reef Pico Led lighting controller Version 1.03 
//created by Harlequin 22-01-11.
//Based on various code librarys avalable on the public domain along with coding compiled by the author.

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>

int whiteFadeOn = 0;
int whiteFadeOff = 0;
int blueFadeOn = 0;
int blueFadeOff = 0;

int whiteLedPin = 9; // White Led chain linked to Digital pin9
int blueLedPin = 10; // Blue Led chain linked to Digital pin10

int blueFadeValue = 0;
int whiteFadeValue = 0;

int userDefMaxWhite = 100; //0-100 user defines the max intensity of the leds
int userDefMaxBlue = 100; //0-100 user defines the max intensity of the leds
int fadeMaxWhite; //variable used when converthing userDefMaxWhite into a PWM value
int fadeMaxBlue; //variable used when converthing userDefMaxBlue into a PWM value

int hour;//variable used for the RTC timed event.
int minute;//variable used for the RTC timed event.

int counter = 0;//counter for PWN

void setup(){
  Serial.begin(9600); //not needed in end product
  rtcStart(); 
}

void loop(){
  debug(); //not needed in end product
  maxCalc();
  ledFade();
  rtcCatch();  
}

void ledFade(){  
  if(counter < 60){
    counter++;
  }
  else{
    
    if(whiteFadeOn == 1){
      if(whiteFadeValue <= fadeMaxWhite) { 
        analogWrite(whiteLedPin, whiteFadeValue);       
        whiteFadeValue = whiteFadeValue+4; // 255/4 = 63.75 i.e. 0-100% takes 63.75 minutes roughly to complete if it takes 1 minutes to complete 1 cycle.
      }
    }

    if(blueFadeOn == 1){
      if(blueFadeValue <= fadeMaxBlue) { 
        analogWrite(blueLedPin, blueFadeValue);       
        blueFadeValue = blueFadeValue+4;
     }
    }  
  
    if(blueFadeOff == 1){
      if(blueFadeValue >= 0) { 
        analogWrite(blueLedPin, blueFadeValue);       
        blueFadeValue = blueFadeValue-4;
      }
    }
  
    if(whiteFadeOff == 1){
      if(whiteFadeValue >= 0) { 
        analogWrite(whiteLedPin, whiteFadeValue);       
        whiteFadeValue = whiteFadeValue-4;
     }
   }
   counter =0;
}
}








void maxCalc(){
  fadeMaxWhite = userDefMaxWhite*2.55;//converts user defined percentage (0-100) into a PWM value (0-255)
  fadeMaxBlue = userDefMaxBlue*2.55;//converts user defined percentage (0-100) into a PWM value (0-255)
}

void rtcCatch(){
  hour = RTC.get(DS1307_HR,false);
  minute = RTC.get(DS1307_MIN,false);
  
  if((hour == 8)&&(minute == 0)){//sets for 08:00
    blueFadeOn = 1;  
  }
  
  if((hour ==8)&&(minute == 2)){//sets for 08:02
    whiteFadeOn = 1;  
  }

  if((hour ==15)&&(minute == 0)){//sets for 15:00
    whiteFadeOn = 0;  
    blueFadeOn = 0;
  }

  if((hour ==20)&&(minute == 0)){//sets for 20:00
    whiteFadeOff = 1;  
  }

  if((hour ==20)&&(minute == 30)){//sets for 20:30
    blueFadeOff = 1;  
  }

  if((hour ==3)&&(minute == 0)){
    whiteFadeOff = 0; 
    blueFadeOff = 0;
     
  }  
}

void debug(){ //not needed in end product
  Serial.print(RTC.get(DS1307_HR,true)); Serial.print(":"); Serial.print(RTC.get(DS1307_MIN,false));Serial.print(":");Serial.print(RTC.get(DS1307_SEC,false));
  Serial.print("      Counter:");    
  Serial.print(counter); 
  Serial.print("      "); 
  Serial.print(RTC.get(DS1307_DATE,false));Serial.print("/"); Serial.print(RTC.get(DS1307_MTH,false));Serial.print("/");Serial.print(RTC.get(DS1307_YR,false));Serial.print(" "); Serial.print(RTC.get(DS1307_DOW,false));
  Serial.print(" Blue LED state:");Serial.print(blueFadeOn);Serial.print(blueFadeOff);Serial.print("   PWM Value:");Serial.print(blueFadeValue);
  Serial.print("      ");
  Serial.print("White LED state:");Serial.print(whiteFadeOn);Serial.print(whiteFadeOff);Serial.print("   PWM Value");Serial.print(whiteFadeValue);
  Serial.println(); 
  delay(1000);
}

void rtcStart(){
  RTC.stop();
  RTC.set(DS1307_SEC,01);        //set the seconds
  RTC.set(DS1307_MIN,59);     //set the minutes
  RTC.set(DS1307_HR,7);       //set the hours
  RTC.set(DS1307_DOW,6);       //set the day of the week
  RTC.set(DS1307_DATE,22);       //set the date
  RTC.set(DS1307_MTH,1);        //set the month
  RTC.set(DS1307_YR,11);         //set the year
  RTC.start();   
}