Got this sketch for controlling 3 banks off leds with pwm dinning, i need to amend the sketch i have to incorporate the second sketch could some on please help, i am guessing all the rtc from the first sketch needs replacing with the second sketch
//Marine Led Controller v1
//created by ReeferGeek 12-02-11.
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
int whiteFadeOn = 0;
int whiteFadeOff = 0;
int blueFadeOn = 0;
int blueFadeOff = 0;
int violetFadeOn = 0;
int violetFadeOff = 0;
int whiteLedPin = 9; // White Led chain linked to Digital pin9
int blueLedPin = 10; // Blue Led chain linked to Digital pin10
int violetLedPin = 11; // violet led chain linked to digital pin 11
int blueFadeValue = 0;
int whiteFadeValue = 0;
int violetFadeValue = 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 userDefMaxViolet = 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 fadeMaxViolet; //variable used when converting userdefmax into 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(violetFadeOn == 1){
if(violetFadeValue <= fadeMaxViolet) {
analogWrite(violetLedPin, violetFadeValue);
violetFadeValue = violetFadeValue+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;
}
}
if(violetFadeOff == 1){
if(violetFadeValue >= 0) {
analogWrite(violetLedPin, violetFadeValue);
violetFadeValue = violetFadeValue-4;
}
}
counter =0;
}
}
void maxCalc(){
fadeMaxWhite = userDefMaxWhite2.55;//converts user defined percentage (0-100) into a PWM value (0-255)
fadeMaxBlue = userDefMaxBlue2.55;//converts user defined percentage (0-100) into a PWM value (0-255)
fadeMaxViolet = userDefMaxViolet*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 == 30)){//sets blue on for 08.30
blueFadeOn = 1;
}
if((hour ==10)&&(minute == 30)){//sets white on for 10.30
whiteFadeOn = 1;
}
if((hour == 21)&&(minute == 00)){//sets violet on for 21.00
violetFadeOn = 1;
}
if((hour ==20)&&(minute == 0)){//sets for 20:00
whiteFadeOff = 1;
}
if((hour ==10)&&(minute == 0)){//sets for 10:00
violetFadeOff = 1;
}
if((hour ==21)&&(minute == 00)){//sets for 21:00
blueFadeOff = 1;
}
}
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.print(" ");
Serial.print("Violet LED state:");Serial.print(violetFadeOn);Serial.print(violetFadeOff);Serial.print(" PWM Value");Serial.print(violetFadeValue);
Serial.println();
delay(1000);
}
void rtcStart(){
RTC.stop();
RTC.set(DS1307_SEC,00); //set the seconds
RTC.set(DS1307_MIN,34); //set the minutes
RTC.set(DS1307_HR,9); //set the hours
RTC.set(DS1307_DOW,06); //set the day of the week
RTC.set(DS1307_DATE,12); //set the date
RTC.set(DS1307_MTH,02); //set the month
RTC.set(DS1307_YR,11); //set the year
RTC.start();
}