/*|||||||||||||||||||||||||| D E F I N E : M O O N L I G H T O N - O F ||||||||||||||||||||||||||||*/
void MoonOn()
{
digitalWrite(moon, HIGH);
}
void MoonOff()
{
digitalWrite(moon, LOW);
}</pre>
/************************************************M O O N P H A S E S ********************************************************************/
int iBlueIntensity; //declare the integer of blue intensity
float fBlueIntensity; //declare the floating point version of blue intensity
emailed you too.Code:/******************************************************************************* * work 4 relay bord, and all goodyes that worked before :) * DS18B20 Temp Sensor and reformat for 20x4 LCD added by Tom, droidninjas@gmail.com * Lunar Phases and heater,fan, backlight added by Martin, liquidartstattoos@gmail.com * BAcklight LCD * ------------------------------ * 0 HEATER A0 FAN * 1 ATS A1 * 2 24V A2 * 3 MOON LED PWM A3 * 4 LCD A4 RTC * 5 LCD PWM A5 RTC * 6 LCD PWM * 7 LCD * 8 TEMP * 9 BACKLTH PWM * 10 LED PWM * 11 LED PWM * 12 LCD * 13 LCD * ------------------------------- **********************************************************************************/ #include <onewire.h> #include <dallastemperature.h> #include "Wire.h" #define DS1307_I2C_ADDRESS 0x68 // Set rtc #include <liquidcrystal.h> // initialize the library with the numbers of pins #define ONE_WIRE_BUS 2 // Define the pin of the DS18B20 /*||||||||||||||||||| L E D D I M M I N G P A R T ||||||||||||||||||||||||||*/ int bluemin = 0 ; // minimmum dimming value of blue LEDs, range of 0-255 int bluemax = 255 ; // maximum dimming value of blue LEDs, range of 0-255 int whitemin = 0 ; // minimum dimming value of white LEDs, range of 0-255 int whitemax = 255 ; // maximum dimming value of white LEDs, range of 0-255 int photoperiod = 540 ; // amount of time array is on at full power in minutes int ontime = 9 ; // when start photoperiod fade in int ramptime = 120 ; // time for LEDs to dim on and off in minutes /*||||||||||||||||||||||||||||||||| P I N ||||||||||||||||||||||||||||||||||||||*/ int blue = 11; // blue LEDs connected to digital pin 11 (pwm) int white = 10; // white LEDs connected to digital pin 10 (pwm) int fan = A0; int ats = 1; int heater = 0; int light = A1; int moon = 3; int backlight = 9; int iBlueIntensity; //declare the integer of blue intensity float fBlueIntensity; //declare the floating point version of blue intensity int bluepercent[] = { 0, 13, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255, 255, 255, 255, 255, 255 }; int whitepercent[]= { 0, 0, 0, 6, 9, 13, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255, 255 }; int abc(sizeof(bluepercent)/sizeof(bluepercent[0])); LiquidCrystal lcd(13,12,7,6,5,4); // initialize the library with the numbers of the interface pins byte newChar[8] = { // Set up the custom icon saule leidzias ir kyla ( 0 ir 1 kyla) (2 ir 3 leidzias) (4 ir 5 menulis ) B01001, B01001, B00101, B00101, B10101, B10111, B01111, B11111 }; byte newChar1[8] = { B10010, B10010, B10100, B10100, B10101, B11101, B11110, B11111 }; byte newChar2[8] = { B11111, B01111, B10111, B10101, B00101, B00101, B01001, B01001 }; byte newChar3[8] = { B11111, B11110, B11101, B10101, B10100, B10100, B10010, B10010 }; byte newChar4[8] = { B00111, B01110, B11100, B11000, B11000, B11100, B01110, B00111 }; byte newChar5[8] = { B01010, B10000, B00010, B01001, B00100, B10000, B00100, B10001 }; byte newChar6[8] = { B01010, B00100, B00001, B11011, B00011, B00001, B01000, B10010 }; byte newChar7[8] = { B10010, B00100, B10000, B11011, B11000, B10000, B00010, B01001 }; OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. /*||||||||||||||||||||||||||||||||||||||| R T C C L O C K D S 1 3 0 7 ||||||||||||||||||||||||||||||||||||*/ byte decToBcd(byte val) // Convert normal decimal numbers to binary coded decimal { return ( (val/10*16) + (val%10) ); } byte bcdToDec(byte val) // Convert binary coded decimal to normal decimal numbers { return ( (val/16*10) + (val%16) ); } void setDateDs1307(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year) { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(0); Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock 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(); } 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()); } /*|||||||||||||||||||||||||||||||||||| D E F I N E : B A C K L I G H T ||||||||||||||||||||||||||||||*/ void backlighton() { analogWrite(backlight, 200); } void backlightoff() { analogWrite(backlight, 50); // If too bright or dim adjust the value accordingly. } /*|||||||||||||||||||||||||||||||||| D E F I N E : L U N A R P H A S E ||||||||||||||||||||||||||||||*/ int moonPhase(int moonYear, int moonMonth, int moonDay) { int dayFromYear, dayFromMonth; double julianDay; int phase; if (moonMonth < 3) //keep the month before march { moonYear--; //take away a year moonMonth += 12; //add an extra 12 months (the year taken away from before) } ++moonMonth; dayFromYear = 365.25 * moonYear; //get days from current year dayFromMonth = 30.6 * moonMonth; //get number of days from the current month julianDay = dayFromYear + dayFromMonth + moonDay - 694039.09; //add them all julianDay /= 29.53; //divide by the length of lunar cycle phase = julianDay; //take integer part julianDay -= phase; //get rid of the int part phase = julianDay*8 + 0.5; //get it between 0-8 and round it by adding .5 phase = phase & 7; //get a number between 1-7 return phase; //1 == new moon, 4 == full moon } /*|||||||||||||||||||||||||||||||||||||||| D E F I N E : O N E S E C O N D ||||||||||||||||||||||||||||||*/ void onesecond() //function that runs once per second while program is running { byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); lcd.setCursor(0, 1); if(hour>0) { if(hour<=12) { lcd.print(hour, DEC); } else { lcd.print(hour, DEC); } } else { lcd.print("12"); } lcd.print(":"); if (minute < 10) {lcd.print("0");} lcd.print(minute, DEC); //lcd.print(":"); //if (second < 10) {lcd.print("0"); } //lcd.print(second, DEC); delay(1000); } /*|||||||||||||||||||||||||| D E F I N E : 24 V O N - O F |||||||||||||||||||||||||||||||||*/ void LightOn() { digitalWrite(light, HIGH); lcd.setCursor(3, 3); lcd.print("+"); } void LightOff() { digitalWrite(light, LOW); lcd.setCursor(3, 3); lcd.print("-"); } /*|||||||||||||||||||||||||| D E F I N E : A T S O N - O F |||||||||||||||||||||||||||||||||*/ void AtsOn() { digitalWrite(ats, LOW); lcd.setCursor(19, 3); lcd.print("+"); } void AtsOff() { digitalWrite(ats, HIGH); lcd.setCursor(19, 3); lcd.print("-"); } /*|||||||||||||||||||||||||| D E F I N E : M O O N L I G H T O N - O F ||||||||||||||||||||||||||||*/ void MoonOn() { digitalWrite(moon, HIGH); } void MoonOff() { digitalWrite(moon, LOW); } /*||||||||||||||||||||||||||||||||||||| S E T U P P I N ||||||||||||||||||||||||||||||||||||||||||||*/ void setup() { pinMode(heater, OUTPUT); pinMode(fan, OUTPUT); pinMode(light, OUTPUT); pinMode(ats, OUTPUT); pinMode(moon, OUTPUT); pinMode(backlight, OUTPUT); sensors.begin(); // Start up the DS18B20 Temp library /*||||||||||||||||||||||||||||||| S E T U P - C L O C K ||||||||||||||||||||||||||||||||||||||||*/ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; Wire.begin(); // Change these values to what you want to set your clock to. // You probably only want to set your clock once and then remove // the setDateDs1307 call. second = 00; minute = 59; hour = 6; dayOfWeek = 25; // Sunday is 0 dayOfMonth = 4; month = 4; year = 11; //setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); //******* set the clock ******* analogWrite(blue, bluemin); analogWrite(white, whitemin); lcd.createChar(0, newChar); lcd.createChar(1, newChar1); lcd.createChar(2, newChar2); lcd.createChar(3, newChar3); lcd.createChar(4, newChar4); lcd.createChar(5, newChar5); lcd.createChar(6, newChar6); lcd.createChar(7, newChar7); lcd.begin(20, 4); //lcd.setCursor(0, 0); //lcd.write(0); //lcd.write(1); lcd.setCursor(3, 0); lcd.print("Jokubo koralai "); //lcd.setCursor(18, 0); //lcd.write(3); //lcd.write(2); lcd.setCursor(11, 1); lcd.print("B:"); lcd.print(33*bluemin/85); lcd.setCursor(16, 1); lcd.print("W:"); lcd.print(33*whitemin/85); lcd.setCursor(11, 2); lcd.print("L: "); lcd.setCursor(0, 2); lcd.print("W: "); lcd.setCursor(0, 3); lcd.print("24V"); lcd.setCursor(5, 3); lcd.print("Fan"); lcd.setCursor(11, 3); lcd.print("Htr"); lcd.setCursor(16, 3); lcd.print("Ats"); } /*|||||||||||||||||||@@@@@@@@@@@@@@@@@@@@@@@@@@@||||| L O O P |||||||@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@||||||||||||||||||||||*/ void loop() { onesecond(); /*||||||||||||||||||||||||||||||||||||||||||||||| L U N A R |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/ float fSecond, fHour, fMinute; //turn the times read from the RTC into float for math ops byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; //declare variables to hold the times getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); //read the RTC times int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes fSecond = (float) second; //sets fSecond as the float version of the integer second from the RTC fMinute = (float) minute; //same as above, but for the minute fHour = (float) hour; //ditto, but for the hour int lunarCycle = moonPhase(year, month, dayOfMonth); //get a value for the lunar cycle //--------MOON LED SETUP----------// if ( ((hour == 7) && (minute < 00)) || (hour < 7))//Off at 730am. { fBlueIntensity = 255; //...then we want the blue LED at the max brightness (255) } else if (hour > 18) //&& (hour < 19)) // On at 5pm { fBlueIntensity = 255 * (((fHour - 16) + (fMinute / 59)) / 7); //...set intensity out of 255 based on time since 17:00 } else { fBlueIntensity = 0; } //---------account for the moon cycle with the 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 is full intensity //----------FLOAT TO INT-------------// iBlueIntensity = (int) fBlueIntensity; //---prepare the intensities to be written to pin----// if (iBlueIntensity < 0) //if the blue intensity is less then 0, set it to 0 { iBlueIntensity = 0; } analogWrite(moon, iBlueIntensity); delay(1000); /*|||||||||||||||||||||||||||||||||||||||| T E M P E R A T U R E DS18B20 |||||||||||||||||||||||||||||||||||*/ sensors.requestTemperatures(); // Send the command to get temperatures delay(750); lcd.setCursor(13, 2); float temp1=0, temp2=0; temp1=sensors.getTempCByIndex(1); lcd.print(sensors.getTempCByIndex(1)); lcd.print((char)223); lcd.print("C"); lcd.setCursor(2, 2); temp2=sensors.getTempCByIndex(0); lcd.print(sensors.getTempCByIndex(0)); lcd.print((char)223); lcd.print("C"); if ( (temp2) > 26.5) { digitalWrite(fan, HIGH); lcd.setCursor(8, 3); lcd.print("+"); } else if ( (temp1) > 38) { digitalWrite(fan, HIGH); lcd.setCursor(8,3); lcd.print("+"); } else { digitalWrite(fan, LOW); lcd.setCursor(8,3); lcd.print("-"); } if ( (temp2) < 24.3 ) { digitalWrite(heater, HIGH); lcd.setCursor(14,3); lcd.print("+"); } else if ( (temp2) > 24.3 ) { digitalWrite(heater, LOW); lcd.setCursor(14,3); lcd.print("-"); } /*|||||||||||||||||||||||||||||||||||||||||||||||||||| ATS |||||||||||||||||||||||||||||||||||||||||||||||||*/ if (hour >= 14) { if ( hour < 22) AtsOff(); } else { AtsOn(); } /*|||||||||||||||||||||||||||||||| R A M P T I M E C A L C U L A T I O N ||||||||||||||||||||||||||||||||*/ int rampup; if (daybyminute >= (ontime*60)) rampup = (((ontime*60) + ramptime) - daybyminute); else rampup = ramptime; int rampdown; if (((ontime * 60) + photoperiod + ramptime) <= daybyminute) rampdown = (((ontime*60) + photoperiod + 2*ramptime) - daybyminute); else rampdown = ramptime; /*|||||||||||||||||||||||||||||||||||||||||| F A D E I N ||||||||||||||||||||||||||||||||||||||||||||||*/ if (daybyminute >= (ontime*60)) { if (daybyminute < ((ontime*60) + ramptime)) { LightOn(); MoonOff(); backlighton(); lcd.setCursor(0, 0); lcd.write(0); lcd.write(1); lcd.setCursor(18, 0); lcd.write(0); lcd.write(1); int i; for (int i = 0; i < abc; i++) { analogWrite(blue, bluepercent[i]); analogWrite(white, whitepercent[i]); lcd.setCursor(13, 1); lcd.print((bluepercent[i]*99)/255); if (i < 10) lcd.print(" "); lcd.setCursor(18, 1); lcd.print((whitepercent[i]*99)/255); if (i < 10) lcd.print(" "); int countdown = ((rampup*60)/abc); while (countdown>0) { onesecond(); countdown--; lcd.setCursor(6, 1); if (countdown < 100) lcd.print ("0"); if (countdown < 10) lcd.print ("0"); lcd.print(countdown); } } } } /*||||||||||||||||||||||||||||||||||||||||||||||| M A X |||||||||||||||||||||||||||||||||||||||||||||*/ if ( daybyminute >= ((ontime * 60) + ramptime)) { if ( daybyminute < ((ontime * 60) + ramptime + photoperiod )) { LightOn(); MoonOff(); backlighton(); analogWrite(blue, 255); analogWrite(white, 255); lcd.setCursor(0, 0); lcd.write(6); lcd.write(7); lcd.setCursor(18, 0); lcd.write(6); lcd.write(7); lcd.setCursor(13, 1); lcd.print(99); lcd.setCursor(18, 1); lcd.print(99); lcd.setCursor(6, 1); lcd.print(" "); } } /*||||||||||||||||||||||||||||||||||||||||||||| F A D E O U T |||||||||||||||||||||||||||||||||||||||||*/ if ( daybyminute >= ((ontime * 60) + photoperiod + ramptime)) { if ( daybyminute < (ontime * 60) + photoperiod + (ramptime *2) ) { LightOn(); MoonOff(); backlighton(); lcd.setCursor(0, 0); lcd.write(2); lcd.write(3); lcd.setCursor(18, 0); lcd.write(2); lcd.write(3); for (int i = abc-1; i >= 0; i--) { analogWrite(blue, bluepercent[i]); analogWrite(white, whitepercent[i]); lcd.setCursor(13, 1); lcd.print((bluepercent[i]*99)/255); if (i < 10) lcd.print(" "); lcd.setCursor(18, 1); lcd.print((whitepercent[i]*99)/255); if (i < 10) lcd.print(" "); int countdown = ((rampdown*60)/abc); // calculates seconds to next step while (countdown>0) { onesecond(); countdown--; lcd.setCursor(6, 1); if (countdown < 100) lcd.print ("0"); if (countdown < 10) lcd.print ("0"); lcd.print(countdown); } } } } //*|||||||||||||||||||||||||||||||||||||||||||||||| Night Time ||||||||||||||||||||||||||||||||||||||||||||||*/ if (daybyminute >= (((ontime * 60) + photoperiod + (2 * ramptime)))) { LightOff(); MoonOn(); backlightoff(); lcd.setCursor(0, 0); lcd.write(4); lcd.write(5); lcd.setCursor(18, 0); lcd.write(4); lcd.write(5); lcd.setCursor(6, 1); lcd.print(" "); } } //*|||||||||||||||||||||||||||||||||||||||||||||||| T H E E N D ||||||||||||||||||||||||||||||||||||||||||*/
Ignore lithuanian coments and title![]()
/*******************************************************************************
* work 4 relay bord, and all goodyes that worked before :)
* DS18B20 Temp Sensor and reformat for 20x4 LCD added by Tom, droidninjas@gmail.com
* Lunar Phases and heater,fan, LCD backlight added by Martin, liquidartstattoos@gmail.com
* ------------------------------
* 0 HEATER A0 FAN
* 1 ATS A1
* 2 24V A2
* 3 MOON LED PWM A3
* 4 LCD A4 RTC
* 5 LCD PWM A5 RTC
* 6 LCD PWM
* 7 LCD
* 8 TEMP
* 9 BACKLTH PWM
* 10 LED PWM
* 11 LED PWM
* 12 LCD
* 13 LCD
* -------------------------------
**********************************************************************************/
#include <onewire.h>
#include <dallastemperature.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68 // Set rtc
#include <liquidcrystal.h> // initialize the library with the numbers of pins
#define ONE_WIRE_BUS 2 // Define the pin of the DS18B20
/*||||||||||||||||||| L E D D I M M I N G P A R T ||||||||||||||||||||||||||*/
int bluemin = 0 ; // minimmum dimming value of blue LEDs, range of 0-255
int bluemax = 255 ; // maximum dimming value of blue LEDs, range of 0-255
int whitemin = 0 ; // minimum dimming value of white LEDs, range of 0-255
int whitemax = 255 ; // maximum dimming value of white LEDs, range of 0-255
int photoperiod = 540 ; // amount of time array is on at full power in minutes
int ontime = 9 ; // when start photoperiod fade in
int ramptime = 120 ; // time for LEDs to dim on and off in minutes
/*||||||||||||||||||||||||||||||||| P I N ||||||||||||||||||||||||||||||||||||||*/
int blue = 11; // blue LEDs connected to digital pin 11 (pwm)
int white = 10; // white LEDs connected to digital pin 10 (pwm)
int fan = A0;
int ats = 1;
int heater = 0;
int light = A1;
int moon = 3;
int backlight = 9;
int bluepercent[] = { 0, 13, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255, 255, 255, 255, 255, 255 };
int whitepercent[]= { 0, 0, 0, 6, 9, 13, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255, 255 };
int abc(sizeof(bluepercent)/sizeof(bluepercent[0]));
/************************************************M O O N P H A S E S ********************************************************************/
int iBlueIntensity; //declare the integer of blue intensity
float fBlueIntensity; //declare the floating point version of blue intensity
LiquidCrystal lcd(13,12,7,6,5,4); // initialize the library with the numbers of the interface pins
byte newChar[8] = { // Set up the custom icon saule leidzias ir kyla ( 0 ir 1 kyla) (2 ir 3 leidzias) (4 ir 5 menulis )
B01001,
B01001,
B00101,
B00101,
B10101,
B10111,
B01111,
B11111
};
byte newChar1[8] = {
B10010,
B10010,
B10100,
B10100,
B10101,
B11101,
B11110,
B11111
};
byte newChar2[8] = {
B11111,
B01111,
B10111,
B10101,
B00101,
B00101,
B01001,
B01001
};
byte newChar3[8] = {
B11111,
B11110,
B11101,
B10101,
B10100,
B10100,
B10010,
B10010
};
byte newChar4[8] = {
B00111,
B01110,
B11100,
B11000,
B11000,
B11100,
B01110,
B00111
};
byte newChar5[8] = {
B01010,
B10000,
B00010,
B01001,
B00100,
B10000,
B00100,
B10001
};
byte newChar6[8] = {
B01010,
B00100,
B00001,
B11011,
B00011,
B00001,
B01000,
B10010
};
byte newChar7[8] = {
B10010,
B00100,
B10000,
B11011,
B11000,
B10000,
B00010,
B01001
};
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
/*||||||||||||||||||||||||||||||||||||||| R T C C L O C K D S 1 3 0 7 ||||||||||||||||||||||||||||||||||||*/
byte decToBcd(byte val) // Convert normal decimal numbers to binary coded decimal
{
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) // Convert binary coded decimal to normal decimal numbers
{
return ( (val/16*10) + (val%16) );
}
void setDateDs1307(byte second,
byte minute,
byte hour,
byte dayOfWeek,
byte dayOfMonth,
byte month,
byte year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
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();
}
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());
}
/*|||||||||||||||||||||||||||||||||||| D E F I N E : B A C K L I G H T ||||||||||||||||||||||||||||||*/
void backlighton()
{
analogWrite(backlight, 200);
}
void backlightoff()
{
analogWrite(backlight, 50); // If too bright or dim adjust the value accordingly.
}
/*|||||||||||||||||||||||||||||||||| D E F I N E : L U N A R P H A S E ||||||||||||||||||||||||||||||*/
int moonPhase(int moonYear, int moonMonth, int moonDay)
{
int dayFromYear, dayFromMonth;
double julianDay;
int phase;
if (moonMonth < 3) //keep the month before march
{
moonYear--; //take away a year
moonMonth += 12; //add an extra 12 months (the year taken away from before)
}
++moonMonth;
dayFromYear = 365.25 * moonYear; //get days from current year
dayFromMonth = 30.6 * moonMonth; //get number of days from the current month
julianDay = dayFromYear + dayFromMonth + moonDay - 694039.09; //add them all
julianDay /= 29.53; //divide by the length of lunar cycle
phase = julianDay; //take integer part
julianDay -= phase; //get rid of the int part
phase = julianDay*8 + 0.5; //get it between 0-8 and round it by adding .5
phase = phase & 7; //get a number between 1-7
return phase; //1 == new moon, 4 == full moon
}
/*|||||||||||||||||||||||||||||||||||||||| D E F I N E : O N E S E C O N D ||||||||||||||||||||||||||||||*/
void onesecond() //function that runs once per second while program is running
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.setCursor(0, 1);
if(hour>0)
{
if(hour<=12)
{
lcd.print(hour, DEC);
}
else
{
lcd.print(hour, DEC);
}
}
else
{
lcd.print("12");
}
lcd.print(":");
if (minute < 10) {lcd.print("0");}
lcd.print(minute, DEC);
//lcd.print(":");
//if (second < 10) {lcd.print("0"); }
//lcd.print(second, DEC);
delay(1000);
}
/*|||||||||||||||||||||||||| D E F I N E : 24 V O N - O F |||||||||||||||||||||||||||||||||*/
void LightOn()
{
digitalWrite(light, HIGH);
lcd.setCursor(3, 3);
lcd.print("+");
}
void LightOff()
{
digitalWrite(light, LOW);
lcd.setCursor(3, 3);
lcd.print("-");
}
/*|||||||||||||||||||||||||| D E F I N E : A T S O N - O F |||||||||||||||||||||||||||||||||*/
void AtsOn()
{
digitalWrite(ats, LOW);
lcd.setCursor(19, 3);
lcd.print("+");
}
void AtsOff()
{
digitalWrite(ats, HIGH);
lcd.setCursor(19, 3);
lcd.print("-");
}
/*||||||||||||||||||||||||||||||||||||| S E T U P P I N ||||||||||||||||||||||||||||||||||||||||||||*/
void setup() {
pinMode(heater, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(light, OUTPUT);
pinMode(ats, OUTPUT);
pinMode(moon, OUTPUT);
pinMode(backlight, OUTPUT);
sensors.begin(); // Start up the DS18B20 Temp library
/*||||||||||||||||||||||||||||||| S E T U P - C L O C K ||||||||||||||||||||||||||||||||||||||||*/
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 00;
minute = 59;
hour = 6;
dayOfWeek = 25; // Sunday is 0
dayOfMonth = 4;
month = 4;
year = 11;
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); //******* set the clock *******
analogWrite(blue, bluemin);
analogWrite(white, whitemin);
lcd.createChar(0, newChar);
lcd.createChar(1, newChar1);
lcd.createChar(2, newChar2);
lcd.createChar(3, newChar3);
lcd.createChar(4, newChar4);
lcd.createChar(5, newChar5);
lcd.createChar(6, newChar6);
lcd.createChar(7, newChar7);
lcd.begin(20,4);
//lcd.setCursor(0, 0);
//lcd.write(0);
//lcd.write(1);
lcd.setCursor(3, 0);
lcd.print("Jokubo koralai");
//lcd.setCursor(18, 0);
//lcd.write(3);
//lcd.write(2);
lcd.setCursor(11, 1);
lcd.print("B:");
lcd.print(33*bluemin/85);
lcd.setCursor(16, 1);
lcd.print("W:");
lcd.print(33*whitemin/85);
lcd.setCursor(11, 2);
lcd.print("L:");
lcd.setCursor(0, 2);
lcd.print("W:");
lcd.setCursor(0, 3);
lcd.print("24V");
lcd.setCursor(5, 3);
lcd.print("Fan");
lcd.setCursor(11, 3);
lcd.print("Htr");
lcd.setCursor(16, 3);
lcd.print("Ats");
}
/*|||||||||||||||||||@@@@@@@@@@@@@@@@@@@@@@@@@@@||||| L O O P |||||||@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@||||||||||||||||||||||*/
void loop()
{
onesecond();
/*||||||||||||||||||||||||||||||||||||||||||||||| L U N A R |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
float fSecond, fHour, fMinute; //turn the times read from the RTC into float for math ops
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year, mil_time;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
fSecond = (float) second; //sets fSecond as the float version of the integer second from the RTC
fMinute = (float) minute; //same as above, but for the minute
fHour = (float) hour; //ditto, but for the hour
int lunarCycle = moonPhase(year, month, dayOfMonth); //get a value for the lunar cycle
//--------MOON LED SETUP----------//
if ( ((hour == 7) && (minute < 00)) || (hour < 7))//Off at 730am.
{
fBlueIntensity = 255; //...then we want the blue LED at the max brightness (255)
}
else if (hour > 17) //&& (hour < 19)) // On at 5pm
{
fBlueIntensity = 255 * (((fHour - 19) + (fMinute / 59)) / 7); //...set intensity out of 255 based on time since 17:00
}
else
{
fBlueIntensity = 0;
}
//---------account for the moon cycle with the 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 is full intensity
//----------FLOAT TO INT-------------//
iBlueIntensity = (int) fBlueIntensity;
//---prepare the intensities to be written to pin----//
if (iBlueIntensity < 0) //if the blue intensity is less then 0, set it to 0
{
iBlueIntensity = 0;
}
//------------and finally, we write the values of the lights to the pins--------------//
analogWrite(moon, iBlueIntensity);
delay(1000);
/*|||||||||||||||||||||||||||||||||||||||| T E M P E R A T U R E DS18B20 |||||||||||||||||||||||||||||||||||*/
sensors.requestTemperatures(); // Send the command to get temperatures
delay(750);
lcd.setCursor(13, 2);
float temp1=0, temp2=0;
temp1=sensors.getTempCByIndex(1);
lcd.print(sensors.getTempCByIndex(1));
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(2, 2);
temp2=sensors.getTempCByIndex(0);
lcd.print(sensors.getTempCByIndex(0));
lcd.print((char)223);
lcd.print("C");
if ( (temp2) > 26.5)
{
digitalWrite(fan, HIGH);
lcd.setCursor(8, 3);
lcd.print("+");
}
else if ( (temp1) > 38)
{
digitalWrite(fan, HIGH);
lcd.setCursor(8,3);
lcd.print("+");
}
else
{
digitalWrite(fan, LOW);
lcd.setCursor(8,3);
lcd.print("-");
}
if ( (temp2) < 24.3 )
{
digitalWrite(heater, HIGH);
lcd.setCursor(14,3);
lcd.print("+");
}
else if ( (temp2) > 24.3 )
{
digitalWrite(heater, LOW);
lcd.setCursor(14,3);
lcd.print("-");
}
/*|||||||||||||||||||||||||||||||||||||||||||||||||||| ATS |||||||||||||||||||||||||||||||||||||||||||||||||*/
if (hour >= 14)
{
if ( hour < 22) AtsOff();
}
else
{
AtsOn();
}
/*|||||||||||||||||||||||||||||||| R A M P T I M E C A L C U L A T I O N ||||||||||||||||||||||||||||||||*/
int rampup;
if (daybyminute >= (ontime*60))
rampup = (((ontime*60) + ramptime) - daybyminute);
else
rampup = ramptime;
int rampdown;
if (((ontime * 60) + photoperiod + ramptime) <= daybyminute)
rampdown = (((ontime*60) + photoperiod + 2*ramptime) - daybyminute);
else
rampdown = ramptime;
/*|||||||||||||||||||||||||||||||||||||||||| F A D E I N ||||||||||||||||||||||||||||||||||||||||||||||*/
if (daybyminute >= (ontime*60))
{ if (daybyminute < ((ontime*60) + ramptime))
{
LightOn();
backlighton();
lcd.setCursor(0, 0);
lcd.write(0);
lcd.write(1);
lcd.setCursor(18, 0);
lcd.write(0);
lcd.write(1);
int i;
for (int i = 0; i < abc; i++)
{
analogWrite(blue, bluepercent[i]);
analogWrite(white, whitepercent[i]);
lcd.setCursor(13, 1);
lcd.print((bluepercent[i]*99)/255);
if (i < 10) lcd.print(" ");
lcd.setCursor(18, 1);
lcd.print((whitepercent[i]*99)/255);
if (i < 10) lcd.print(" ");
int countdown = ((rampup*60)/abc);
while (countdown>0)
{
onesecond();
countdown--;
lcd.setCursor(6, 1);
if (countdown < 100) lcd.print ("0");
if (countdown < 10) lcd.print ("0");
lcd.print(countdown);
}
}
}
}
/*||||||||||||||||||||||||||||||||||||||||||||||| M A X |||||||||||||||||||||||||||||||||||||||||||||*/
if ( daybyminute >= ((ontime * 60) + ramptime))
{
if ( daybyminute < ((ontime * 60) + ramptime + photoperiod ))
{
LightOn();
backlighton();
analogWrite(blue, 255);
analogWrite(white, 255);
lcd.setCursor(0, 0);
lcd.write(6);
lcd.write(7);
lcd.setCursor(18, 0);
lcd.write(6);
lcd.write(7);
lcd.setCursor(13, 1); //Poss Problem
lcd.print(99); //Poss Problem
lcd.setCursor(18, 1); //Poss Problem
lcd.print(99); //Poss Problem
lcd.setCursor(6, 1);
lcd.print(" ");
}
}
/*||||||||||||||||||||||||||||||||||||||||||||| F A D E O U T |||||||||||||||||||||||||||||||||||||||||*/
if ( daybyminute >= ((ontime * 60) + photoperiod + ramptime))
{
if ( daybyminute < (ontime * 60) + photoperiod + (ramptime *2) )
{
LightOn();
backlighton();
lcd.setCursor(0, 0);
lcd.write(2);
lcd.write(3);
lcd.setCursor(18, 0);
lcd.write(2);
lcd.write(3);
for (int i = abc-1; i >= 0; i--)
{
analogWrite(blue, bluepercent[i]);
analogWrite(white, whitepercent[i]);
lcd.setCursor(13, 1);
lcd.print((bluepercent[i]*99)/255);
if (i < 10) lcd.print(" ");
lcd.setCursor(18, 1);
lcd.print((whitepercent[i]*99)/255);
if (i < 10) lcd.print(" ");
int countdown = ((rampdown*60)/abc); // calculates seconds to next step
while (countdown>0)
{
onesecond();
countdown--;
lcd.setCursor(6, 1);
if (countdown < 100) lcd.print ("0");
if (countdown < 10) lcd.print ("0");
lcd.print(countdown);
}
}
}
}
//*|||||||||||||||||||||||||||||||||||||||||||||||| Night Time ||||||||||||||||||||||||||||||||||||||||||||||*/
if (daybyminute >= (((ontime * 60) + photoperiod + (2 * ramptime))))
{
LightOff();
backlightoff();
lcd.setCursor(0, 0);
lcd.write(4);
lcd.write(5);
lcd.setCursor(18, 0);
lcd.write(4);
lcd.write(5);
lcd.setCursor(6, 1);
lcd.print(" ");
}
}
//*|||||||||||||||||||||||||||||||||||||||||||||||| T H E E N D ||||||||||||||||||||||||||||||||||||||||||*/
Well it took me a week to learn how to write a sketch, and be able to figure out how to incorporate a 128x64 KS0108 GLCD into a Katchupoy original sketch.
Thanks for all of your guys hard work, especially Molehs who was able to give me a push in the right direction on working with a GLCD.
I felt I had to get this working so I could contribute to this very informative thread, and I hope someone could use this.
I almost gave up on the GLCD, but I just had to have all that extra real estate to be able to play with bitmaps.
Well its late and my kids are going to wake me up in a couple hours, I will have pictures and updates shortly, so goodnight.
Maybe tonight I will be able to dream about something else other than sketches for my arduino.:spin2:
PS the ramptimes are set to 2 minutes for testing purposes and I set the blue white display to show percentage 10%-100%.
Sweet....would love to see how it turned out and how much room you have left on the display to be able to show more readings.
Very Cool.....because you mentioned something about your GLCD I dusted the one that came with mine off to play with too....remember to add your info to that sketch....u deserve the credit.
The fastest way to test the dimming and all the other outputs is by using the 3mm LEDs that came with your kit if you bought it on ebay.....it's how I test it all on the breadboard before moving to my LED drivers and relays....I let everything run for about a week on the 1.5v LEDs though before going forward.I run both the uno and mega on 9v 1A wallwart.
Do you remember this? This is the original wiring diagram "with pot" and without Arduino...
![]()
Well the only change we will do with this wiring is to "tap" or "cut" the negative side from the "10v" signal going to the LED driver.
![]()
This diagram is only for one channel and for one Arduino pin. It means 1 ramp up and down. One channel can have 1,2 or 4 LED drivers connected to it, but this only means that all of them will ramp up and ramp down at the same time.
If you need to put another channel, example... white, then you just need to duplicate the wiring, resistor, transistor and use another arduino pin.