hello guys:
i trying build aquarium led lighting controller arduino mega (atmega1280chip), plus rtc1307 real time clocking module.
basically have 6 channels (different colors) connected arduino pwm pins cat4101 driver, not using resistors nor else on circuit, cat4101 , rset resistor.
now question is, have taken several codes web dimmering leds using rtc time module, none of them works on arduino mega, took on pico reef led other website, need, doesn't work either.
is there code out there or easy can use pwm leds using rtc arduino mega?
also should use type of resistor between pwm ping on cat4101 , arduino pin?
this circuit using:
en/pwm pin on cat4101 goes directly digital pins 7-12 on arduino mega.
any or easy code arduinopwm+rtc can provide me can test circuit?
thank in advace.
steve.
i trying build aquarium led lighting controller arduino mega (atmega1280chip), plus rtc1307 real time clocking module.
basically have 6 channels (different colors) connected arduino pwm pins cat4101 driver, not using resistors nor else on circuit, cat4101 , rset resistor.
now question is, have taken several codes web dimmering leds using rtc time module, none of them works on arduino mega, took on pico reef led other website, need, doesn't work either.
is there code out there or easy can use pwm leds using rtc arduino mega?
also should use type of resistor between pwm ping on cat4101 , arduino pin?
this circuit using:
en/pwm pin on cat4101 goes directly digital pins 7-12 on arduino mega.
any or easy code arduinopwm+rtc can provide me can test circuit?
thank in advace.
steve.
this 1 of codes have found , fit perfect needs, when uploaded arduino mega board leds keeps on @ 100%..
code: [select]
//2.7 gallon pico reef led light controller version 1.06
//code written plant_arms 2012-08-31
//based on various code libraries avalable on public domain along coding compiled author.
#include <wire.h>
#include "rtclib.h"
rtc_ds1307 rtc;
int bluepin = 9; // blue leds connected digital pin5
int whitepin = 10; // white leds connected digital pin6
double bluefadevalue = 255;
double whitefadevalue = 255;
double userwhitemax = 4; // maximum percentage intensity of white leds, 0-100 user defined
double userbluemax = 9; // maximum percentage intensity of blue leds, 0-100 user defined
double bluemaxpwm; // variable used convert userbluemax value pwm value
double whitemaxpwm; // variable used convert userwhitemax value pwm value
int second;
int hour;
int minute;
int bluelightson = 9; // time of day (hour, 24h clock) begin blue lights fading on
int whitelightson = 10; // time of day (hour, 24h clock) begin white lights fading on
int whitelightsoff = 20; // time of day (hour, 24h clock) begin white lights fading out
int bluelightsoff = 21; // time of day (hour, 24h clock) begin blue lights fading out
double fadetime = 60; // amount of time in minutes fade in/out last **must in 60 minute increments**
void setup () {
serial.begin(115200);
wire.begin();
rtc.begin();
if (!rtc.isrunning()) { //uncomment ! able reset datetime value
// allow set rtc current computer date , time if uncommented , compiled
//rtc.adjust(datetime(__date__, __time__));
}
}
void loop () {
setfade();
ledrtc();
serialout();
}
//void setfade class used covert user percentage input pwm value , set white/blue
void setfade(){
bluemaxpwm = (userbluemax*2.55); //converts user input value (0-100) pwm value (0-255)
whitemaxpwm = (userwhitemax*2.55); //converts user input value (0-100) pwm value (0-255)
}
//void ledrtc class control leds ds1307 timer, absolute value , using time periods(<= etc) gain correct fade position in case of power outage
void ledrtc(){
datetime = rtc.now();
hour = now.hour();
minute = now.minute();
second = now.second();
int totbluehron = hour - bluelightson;
int totbluehroff = hour - bluelightsoff;
int totwhitehron = hour - whitelightson;
int totwhitehroff = hour - whitelightsoff;
int totalminute = minute;
abs(totbluehron);
abs(totbluehroff);
abs(totwhitehron);
abs(totwhitehroff);
abs(totalminute);
int totalblueon = ((totbluehron*60) + totalminute);
int totalblueoff = ((totbluehroff*60) + totalminute);
int totalwhiteon = ((totwhitehron*60) + totalminute);
int totalwhiteoff = ((totwhitehroff*60) + totalminute);
//fades on blue lights bluelightson through bluelightson plus fadetime , outputs light intensity based on current time
if((hour >= bluelightson)&&(hour < (bluelightson+(fadetime/60)))&&(totalblueon < fadetime)){
bluefadevalue = 255-(bluemaxpwm*(totalblueon/fadetime));
analogwrite(bluepin, bluefadevalue);
}
//fades on white lights whitelightson whitelightson plus fadetime , outputs light intensity based on current time
if((hour >= whitelightson)&&(hour <= (whitelightson+(fadetime/60)))&&(totalwhiteon <= fadetime)){
whitefadevalue = 255-(whitemaxpwm*(totalwhiteon/fadetime));
analogwrite(whitepin, whitefadevalue);
}
//puts blue lights full if fade in period complete , less bluelightsoff, full 10 20:59
if((hour >= (bluelightson+(fadetime/60)))&&(hour < bluelightsoff)){
bluefadevalue = 255-bluemaxpwm;
analogwrite(bluepin, bluefadevalue);
}
//puts white lights full if fade in period complete , less whitelightsoff, full 11 19:59
if((hour >= (whitelightson+(fadetime/60)))&&(hour < whitelightsoff)){
whitefadevalue = 255-whitemaxpwm;
analogwrite(whitepin, whitefadevalue);
}
//fades out whites whitelightsoff whitelightsoff plus fadetime , outputs light intensity based on current time
if((hour >= whitelightsoff)&&(hour < (whitelightsoff+(fadetime/60)))&&(totalwhiteoff <= fadetime)){
whitefadevalue = 255-(whitemaxpwm - (whitemaxpwm*(totalwhiteoff/fadetime)));
analogwrite(whitepin, whitefadevalue);
}
//fade out blues bluelightsoff bluelightsoff plus fadetime , outputs light intensity based on current time
if((hour >= bluelightsoff)&&(hour < (bluelightsoff+(fadetime/60)))&&(totalblueoff <= fadetime)){
bluefadevalue = 255-(bluemaxpwm - (bluemaxpwm*(totalblueoff/fadetime)));
analogwrite(bluepin, bluefadevalue);
}
//this sets white lights off end of whitelightsoff plus fadetime midnight
if((hour >= (whitelightsoff+(fadetime/60))&&(hour <= 24))){
whitefadevalue = 255;
analogwrite(whitepin, whitefadevalue);
}
//this sets blue lights off end of bluelightsoff plus fadetime midnight
if((hour >= (bluelightsoff+(fadetime/60))&&(hour < 24))){
bluefadevalue = 255;
analogwrite(bluepin, bluefadevalue);
}
//this sets white lights off midnight whitelightson in case of reset of power outage
if((hour >= 0)&&(hour < whitelightson)){
whitefadevalue = 255;
analogwrite(whitepin, whitefadevalue);
}
//this sets blue lights off midnight bluelightson in case of reset or power outage
if((hour >= 0)&&(hour < bluelightson)){
bluefadevalue = 255;
analogwrite(bluepin, bluefadevalue);
}
}
//serialout class output print statements serial lcd display, time, temp, , light prcnt
void serialout(){
//datetime = rtc.now();
//print time pulled in spaced 0's
if (hour < 10) {
serial.print('0');
serial.print(hour);}
else {serial.print(hour);}
serial.print(':');
if (minute < 10) {
serial.print('0');
serial.print(minute);}
else {serial.print(minute);}
serial.print(':');
if (second < 10) {
serial.print('0');
serial.print(second);}
else {
serial.print(second);}
serial.print(100-(whitefadevalue/2.55));
serial.print("%");
serial.print(100-(bluefadevalue/2.55));
serial.print("%");
serial.println();
delay(1000);
}
Arduino Forum > Using Arduino > Project Guidance > Question about PWM+RTC on Mega1280
arduino
Comments
Post a Comment