Moon phase for tank light
hi everyone.
i need implement lunar cycle led light tank.
hi have 4 bank of led, 2 blues , 2 whites, , led smd 5050 simulate moon phase.
the cat 4101 driving 2 blues , whites, , tip 120 driving 5050's.
i working arduino uno rev 3.
in future want add wheter sketch aswell, newbie, , moon phase enough.
i have symple sketch taht like, cause simple, , update leds seconds.
of course period part it's test now...
now moon phase like:
the answer how can tie 2 pieces of code?
thanks can me
i need implement lunar cycle led light tank.
hi have 4 bank of led, 2 blues , 2 whites, , led smd 5050 simulate moon phase.
the cat 4101 driving 2 blues , whites, , tip 120 driving 5050's.
i working arduino uno rev 3.
in future want add wheter sketch aswell, newbie, , moon phase enough.
i have symple sketch taht like, cause simple, , update leds seconds.
code: [select]
#include "wire.h"
#include
#define ds1307_address 0x68 // address
const int blue1pin = 10;
const int blue2pin = 5;
const int white3pin = 3;
const int white4pin = 11;
const unsigned long hour = 60 * 60;
const unsigned long minute = 60;
const int target_brightness = (255 * 4 / 5); // target brightness 3/4 of full
liquidcrystal lcd(12, 13, 4, 6, 7, 8);
/***** rtc functions *******/
// convert normal decimal numbers binary coded decimal
byte dectobcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// 1) sets date , time on ds1307
// 2) starts clock
// 3) sets hour mode 24 hour clock
// assumes you're passing in valid numbers.
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_address);
wire.write(0);
wire.write(dectobcd(second));
wire.write(dectobcd(minute));
wire.write(dectobcd(hour));
wire.write(dectobcd(dayofweek));
wire.write(dectobcd(dayofmonth));
wire.write(dectobcd(month));
wire.write(dectobcd(year));
wire.endtransmission();
}
// gets date , time ds1307
void getdateds1307(byte *second,
byte *minute,
byte *hour,
byte *dayofweek,
byte *dayofmonth,
byte *month,
byte *year)
{
}
void setup()
{
wire.begin();
byte second, minute, hour, dayofweek, dayofmonth, month, year;
wire.begin();
// change these values want set clock to.
// want set clock once , remove
// setdateds1307 call.
second = 55;
minute = 03;
hour = 14;
dayofweek = 4; // sunday 0
dayofmonth = 4;
month = 8;
year = 11;
setdateds1307(second, minute, hour, dayofweek, dayofmonth, month, year);
}
// convert binary coded decimal normal decimal numbers
byte bcdtodec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void loop()
{
///// get time rtc rtchour, rtcminute, rtcsecond
// gets date , time ds1307
// set register pointer 0 (second)
wire.begintransmission(ds1307_address);
wire.write((byte)0);
wire.endtransmission();
// read second, minute, , hour
wire.requestfrom(ds1307_address, 3);
int rtcsecond = bcdtodec(wire.read());
int rtcminute = bcdtodec(wire.read());
int rtchour = bcdtodec(wire.read() & 0b111111); //24 hour time
lcd.setcursor(0, 0);
lcd.print(rtchour, dec);
lcd.print(":");
lcd.print(rtcminute, dec);
lcd.print(":");
lcd.print(rtcsecond, dec);
lcd.print(" ");
unsigned long time = rtchour * hour + rtcminute * minute + rtcsecond; // time in seconds
analogwrite(blue1pin, brightness(time, 14*hour, 14*hour+7*minute));
analogwrite(blue2pin, brightness(time, 14*hour+1*minute, 14*hour+6*minute));
analogwrite(white3pin, brightness(time, 14*hour+2*minute, 14*hour+4*minute));
analogwrite(white4pin, brightness(time, 14*hour+3*minute, 14*hour+5*minute));
delay(1000);
}
byte brightness(unsigned long time, unsigned long fadeupstart, unsigned long fadedownstart)
{
// mid day, light @ maximum brightness
if (time >= fadeupstart + 1*minute && time <= fadedownstart)
return target_brightness;
// dawn: fade light
if (time >= fadeupstart && time <= fadeupstart + 1*minute) //fade up
{
unsigned long seconds = time - fadeupstart; // number of seconds fade time
return target_brightness * seconds / (minute*1); // fade based on portion of interval completed.
}
// evening: fade down light
if (time >= fadedownstart && time <= <= fadedownstart + 1*minute) // fading down
{
unsigned long seconds = (fadedownstart + (minute*1)) - time; // number of seconds remaining in fade time
return target_brightness * seconds / (minute*1); // fade down based on portion of interval left.
}
// remaining times night , lights off
return 0; // shouldn't here
}
of course period part it's test now...
now moon phase like:
code: [select]
int moon = 5;
int iblueintensity; //declare integer of blue intensity
float fblueintensity; //declare floating point version of blue intensity
// rtc variables
byte second, rtcmins, oldmins, rtchrs, oldhrs, dayofweek, dayofmonth, month, year, psecond;
float fsecond, fhour, fminute; //turn times read rtc float math ops
byte second, minute, hour, dayofweek, dayofmonth, month, year; //declare variables hold times
getdateds1307(&second, &rtcmins, &rtchrs, &dayofweek, &dayofmonth, &month, &year);
fsecond = (float) second; //sets fsecond float version of integer second rtc
fminute = (float) minute; //same above, minute
fhour = (float) hour; //ditto, hour
int lunarcycle = moonphase(year, month, dayofmonth); //get value lunar cycle
if ( ((hour == 14) && (minute < 7)) || (hour < 14))//off @ 730am.
{
fblueintensity = 0; //...then want blue led @ max brightness (255)
}
else if (hour > 14) //&& (hour < 19)) // on @ 5pm
{
fblueintensity = 255 * (((fhour - 17) + (fminute / 59)) / 7); //...set intensity out of 255 based on time since 17:00
}
else
{
fblueintensity = 0;
}
//---------account moon cycle blue leds---------//
if (lunarcycle == 0) //new moon
{
fblueintensity /= 2;
}
if ((lunarcycle == 1) || (lunarcycle == 7)) //cresent
{
fblueintensity /= 1.75 ;
}
if ((lunarcycle == 2) || (lunarcycle == 6)) //half moon
{
fblueintensity /= 1.5;
}
if ((lunarcycle == 3) || (lunarcycle == 5)) //gibbous
{
fblueintensity /= 1.25;
}
//full moon full intensity
//----------float int-------------//
iblueintensity = (int) fblueintensity;
bby
//---prepare intensities written pin----//
if (iblueintensity < 0) //if blue intensity less 0, set 0
{
iblueintensity = 0;
}
analogwrite(moon, iblueintensity);
delay(1000);
the answer how can tie 2 pieces of code?
thanks can me
are trying adjust on/off time sunset/sunrise?
Arduino Forum > Using Arduino > LEDs and Multiplexing > Moon phase for tank light
arduino
Comments
Post a Comment