I have a vivarium program with timers and one wire temperature readout, I want to add a 4 channel dimmer for the spotlights using the temperature to control the dimmer channels.
here is the dimmer i have purchased.
[4CH AC DIMMER V2 SSR RELAY BOARD ARDUINO 2A 50HZ 60HZ 110V 220V | eBay]
at present the program works with a 3.2" touch screen with 12 timers to control all lights on and off times. i am looking for someone to help with the programming as i am not good enough to program this and at 65 am struggling to learn new programming methods.
You've come to the right place. Post the code you have so far. Please use BBS code tags...
[code]
{your code goes here}
[/code]
Or markdown code tags...
``` cpp
{your code goes here}
```
I have a mega with Dallas 1 wire system and want to use that to control the 4 channel dimmer
{// LEGAL DISCLAIMER:
// Jarduino Aquarium Controller v.1.1 and v.1.2, Copyright 2011, 2012 Jamie M. Jardin.
// I'm providing this program as free software with the sole intent on furthering
// DIY Aquarium Lighting, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You may modify and/or use
// it under the terms of the GNU General Public License as published by the Free
// Software Foundation version 3 of the License, or (at your option) any later
// version. However if you intend on using the program (either in its entirety or any
// part of it) in any way, shape, or form for PROFIT, you MUST contact me and obtain
// my EXPRESS WRITTEN CONSENT (contact information is provided above).
// VIOLATORS WILL BE PROSECUTED TO THE FULLEST EXTENT OF THE LAW.
//
//************************************************************************************/
//LIBRARIES
#include <UTFT.h> //uncomment if using UTFT library
#include <URTouch.h>
//#include <avr/pgmspace.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS1307.h>
#include <EEPROM.h>
#include "writeAnything.h"
//Default Controller Settings
boolean RECOM_RCD = true; //For Mean Well drivers change "true" to "false"
//LCD TOUCH PANEL and ITDB02 MEGA SHIELD v1.1 (Mega Shield utilizes pins 5V, 3V3, GND, 2-6, 20-41, & (50-53 for SD Card))
URTouch myTouch(6,5,4,3,2);
//UTFT myGLCD(ITDB32S,38,39,40,41); //ITDB32S=SSD1289 / CTE32_R2 or ILI9341_16 = ILI9341
UTFT myGLCD(ILI9341_16,38,39,40,41); // TFT ILI9341_16b
//Initialize the DS1307
DS1307 rtc(20, 21);
DS1307_RAM ramBuffer; //Declare a buffer for use
Time t, t_temp; //Init Time-data structure
int rtcSetMin, rtcSetHr, rtcSetDy,
rtcSetMon, rtcSetYr;
int setCalendarFormat = 0; //DD/MM/YYYY=0 || Month DD, YYYY=1 (change in prog)
int displayDOW = 0; //Hide=0 || Show=1 (change in prog)
int setTimeFormat = 0; //24HR=0 || 12HR=1 (change in prog)
int AM_PM, yTime; //Setting clock stuff
int timeDispH, timeDispM,
xTimeH, xTimeM10, xTimeM1,
xTimeAMPM, xColon;
String time, day;
int setClockOrBlank = 0; //Clock Screensaver=0 || Blank Screen=1 (change in prog)
int setScreensaverOnOff = 0; //OFF=0 || ON=1 Turns it ON/OFF (change in prog)
int setScreensaverDOWonOff = 0; //OFF=0 || ON=1 Shows/Hides DOW in Screensaver (change in prog)
int SS_DOW_x; //Moves the DOW to correct position
int setSSmintues; //Time in (minutes) before Screensaver comes on (change in program)
int TempSSminutes; //Temporary SetSSminutes used in calcs and prints, etc.
int setScreenSaverTimer; //how long in (minutes) before Screensaver comes on (change in program)
int screenSaverCounter = 0; //counter for Screen Saver
boolean SCREEN_RETURN = true; //Auto Return to mainScreen() after so long of inactivity
int returnTimer = 0; //counter for Screen Return
int setReturnTimer; //Return to main screen 75% of time before the screensaver turns on
//Declare which fonts to be utilized
//extern uint8_t TinyFont[];
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
int LARGE=0;
int SMALL=1;
//Relay Timers
const int timer1 = A0; //Timer 1 to be defined
const int timer2 = A1; //Timer 2 to be defined
const int timer3 = A2; //Timer 3 to be defined
const int timer4 = A12; //Timer 4 to be defined
const int timer5 = A4; //Timer 5 to be defined
const int timer6 = A5; //Timer 6 to be defined
const int timer7 = A6; //Timer 7 to be defined
const int timer8 = A7; //Timer 8 to be defined
const int timer9 = A8; //Timer 9 to be defined
const int timer10 = A9; //Timer 10 to be defined
const int timer11 = A10; //Timer 11 to be defined
const int timer12 = A11; //Timer 12 to be defined
// DS18B20 Temperature sensors plugged into pin 51 (Water, Hood, & Sump)
OneWire OneWireBus(51); //(51) Choose a digital pin
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&OneWireBus);
// Assign the addresses of temperature sensors. Add/Change addresses as needed.
DeviceAddress viv1Thermometer = { 0x28, 0xFF, 0x51, 0xAF, 0xC4, 0x17, 0x04, 0x0D };
DeviceAddress viv2Thermometer = { 0x28, 0xFF, 0xB1, 0xA3, 0x24, 0x17, 0x03, 0x81 };
DeviceAddress viv3Thermometer = { 0x28, 0xFF, 0xB5, 0xAC, 0xC4, 0x17, 0x05, 0x1E };
DeviceAddress viv4Thermometer = { 0x28, 0xFF, 0x2D, 0xAC, 0xC4, 0x17, 0x04, 0xC9 };
DeviceAddress viv5Thermometer = { 0x28, 0xFF, 0xA3, 0xB2, 0xC4, 0x17, 0x04, 0x8D };
DeviceAddress viv6Thermometer = { 0x28, 0xFF, 0x7B, 0xAE, 0xC4, 0x17, 0x05, 0x99 };
DeviceAddress viv7Thermometer = { 0x28, 0xFF, 0x2F, 0xDC, 0x80, 0x14, 0x02, 0xC5 };
DeviceAddress viv8Thermometer = { 0x28, 0xFF, 0x9F, 0xAE, 0xC4, 0x17, 0x04, 0x02 };
float tempv1 = 0; //viv1 temperature values
float tempv2 = 0; //viv2 temperature values
float tempv3 = 0; //viv3 temperature values
float tempv4 = 0; //viv4 temperature values
float tempv5 = 0; //viv5 temperature values
float tempv6 = 0; //viv6 temperature values
float tempv7 = 0; //viv7 temperature values
float tempv8 = 0; //viv8 temperature values
float setTempC = 0.0; //Desired Water Temperature (User input in program)
float setTempF = 0.0;
float offTempC = 0.0; //Desired Water Temp. Offsets for Heater & Chiller (User input in program)
float offTempF = 0.0;
float alarmTempC = 0.0; //Temperature the Alarm will sound (User input in program)
float alarmTempF = 0.0;
boolean tempCoolflag = 0; //1 if cooling on
boolean tempHeatflag = 0; //1 if heating on
boolean tempAlarmflag = 0; //1 if alarm on
long intervalAlarm = 1000 * 30; //Interval to beep the Alarm (1000 * seconds)
float temp2beS; //Temporary Temperature Values
float temp2beO; //Temporary Temperature Values
float temp2beA; //Temporary Temperature Values
int setTempScale = 0; //Celsius=0 || Fahrenheit=1 (change in prog)
String degC_F; //Used in the Conversion of Celsius to Fahrenheit
int dispScreen=0; //0-Main Screen, 1-Menu, 2-Clock Setup, 3-Temp Control,
//4-LED Test Options, 5-Test LED Arrays, 6-Test Individual
//LED Colors, 7-Choose LED Color, 8-View Selected Color
//Values, 9-Change Selected Color Array Values
//10-Wavemaker, 11-Wavemaker Settings, 12-General
//Settings, 13-Automatic Feeder, 14-Set Feeder Timers,
//15-About
int x, y; //touch coordinates
long previousMillisFive = 0; //Used in the Main Loop (Checks Time,Temp,LEDs,Screen)
long previousMillisAlarm = 0; //Used in the Alarm
long previousMillisCt = 0; //stores the last update for the Countdown Timer
long intervalCt = 1000; //One Second Interval for Countdown Timer
int countDown = 5*60 + 0; //Countdown for 5 minutes and zero seconds
int MIN_O = 5; //Start the Time at 5 (for looks only)
int SEC_T = 0;
int SEC_O = 0;
int min_cnt; //Used to determine the place in the color arrays
int ONtime, OFFtime;
int on1,on2,on3,on4,on5,on6,on7,on8,on9,on10,on11,on12; //timers 1-12
int off1,off2,off3,off4,off5,off6,off7,off8,off9,off10,off11,off12; //timers 1-12
int timerPage; //gets you back to the right place
int slctRelay;
int slctONtm, slctOFFtm;
byte timer1Status; //timer status 1 (Manual Control)
byte timer2Status; //timer status 2
byte timer3Status; //timer status 3
byte timer4Status; //timer status 4
byte timer5Status; //timer status 5
byte timer6Status; //timer status 6
byte timer7Status; //timer status 7
byte timer8Status; //timer status 8
byte timer9Status; //timer status 9
byte timer10Status; //timer status 10
byte timer11Status; //timer status 11
byte timer12Status; //timer status 12
/**************************** CHOOSE OPTION MENU BUTTONS *****************************/
const int tanD[]= {10, 29, 155, 59}; //"TIME and DATE" settings
const int temC[]= {10, 69, 155, 99}; //"H2O TEMP CONTROL" settings
const int wave[]= {10, 109, 155, 139}; //"Wavemaker CONTROL" settings
const int gSet[]= {10, 149, 155, 179}; //"GENERAL SETTINGS" page
const int TimerS[]= {165, 69, 310, 99}; //"TIMER SETTINGS" menu
const int about[]= {165, 149, 310, 179}; //"ABOUT" program information
/**************************** TIME AND DATE SCREEN BUTTONS ***************************/
const int houU[]= {110, 22, 135, 47}; //hour up
const int minU[]= {180, 22, 205, 47}; //min up
const int ampmU[]= {265, 22, 290, 47}; //AM/PM up
const int houD[]= {110, 73, 135, 98}; //hour down
const int minD[]= {180, 73, 205, 98}; //min down
const int ampmD[]= {265, 73, 290, 98}; //AM/PM down
const int dayU[]= {110, 112, 135, 137}; //day up
const int monU[]= {180, 112, 205, 137}; //month up
const int yeaU[]= {265, 112, 290, 137}; //year up
const int dayD[]= {110, 162, 135, 187}; //day down
const int monD[]= {180, 162, 205, 187}; //month down
const int yeaD[]= {265, 162, 290, 187}; //year down
/*************************** H2O TEMP CONTROL SCREEN BUTTONS *************************/
const int temM[]= {90, 49, 115, 74}; //temp. minus
const int temP[]= {205, 49, 230, 74}; //temp. plus
const int offM[]= {90, 99, 115, 124}; //offset minus
const int offP[]= {205, 99, 230, 124}; //offset plus
const int almM[]= {90, 149, 115, 174}; //alarm minus
const int almP[]= {205, 149, 230, 174}; //alarm plus
//These Buttons are made within the function
/******************* SET AUTOMATIC FISH FEEDING TIMES BUTTONS ************************/
const int houP[]= {110, 38, 135, 63}; //hour up
const int minP[]= {180, 38, 205, 63}; //min up
const int ampmP[]= {265, 38, 290, 63}; //AM/PM up
const int houM[]= {110, 89, 135, 114}; //hour down
const int minM[]= {180, 89, 205, 114}; //min down
const int ampmM[]= {265, 89, 290, 114}; //AM/PM down
/***************************** MISCELLANEOUS BUTTONS *********************************/
const int backGS[]= {4, 200, 78, 220}; //BACK
const int nextGS[]= {83, 200, 157, 220}; //NEXT
const int prSAVEgs[]= {162, 200, 236, 220}; //SAVE
const int canCgs[]= {241, 200, 315, 220}; //CANCEL
const int HoodFanTm[]= {90, 56, 115, 81}; //Hood Fan Temp -
const int HoodFanTp[]= {205, 56, 230, 81}; //Hood Fan Temp +
const int SumpFanTm[]= {90, 147, 115, 172}; //Sump Fan Temp -
const int SumpFanTp[]= {205, 147, 230, 172};//Sump Fan Temp +
const int back[]= {5, 200, 105, 220}; //BACK
const int prSAVE[]= {110, 200, 210, 220}; //SAVE
const int canC[]= {215, 200, 315, 220}; //CANCEL
void drawUpButtonSlide(int x, int y)
{
myGLCD.setColor(64, 64, 128);
myGLCD.fillRoundRect(x, y, x+30, y+22);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(x, y, x+30, y+22);
myGLCD.setColor(128, 128, 255);
for (int i=0; i<15; i++)
myGLCD.drawLine(x+5+(i/1.5), y+18-i, x+26-(i/1.5), y+18-i);
}
void drawDownButtonSlide(int x, int y)
{
myGLCD.setColor(64, 64, 128);
myGLCD.fillRoundRect(x, y, x+30, y+22);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(x, y, x+30, y+22);
myGLCD.setColor(128, 128, 255);
for (int i=0; i<15; i++)
myGLCD.drawLine(x+5+(i/1.5), y+4+i, x+26-(i/1.5), y+4+i);
}
void drawUpButton(int x, int y)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(x, y, x+25, y+25);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(x, y, x+25, y+25);
for (int i=0; i<15; i++)
myGLCD.drawLine(x+3+(i/1.5), y+19-i, x+22-(i/1.5), y+19-i);
}
void drawDownButton(int x, int y)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(x, y, x+25, y+25);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(x, y, x+25, y+25);
for (int i=0; i<15; i++)
myGLCD.drawLine(x+3+(i/1.5), y+6+i, x+22-(i/1.5), y+6+i);
}
void drawUpDownSmall(int x, int y)
{ myGLCD.setColor(0, 255, 0);
myGLCD.drawRoundRect(x, y, x+72, y+20);
myGLCD.fillRoundRect(x, y, x+20, y+20);
myGLCD.fillRoundRect(x+52, y, x+72, y+20);
myGLCD.setColor(0, 0, 0);
for (int i=0; i<11; i++)
{myGLCD.drawLine(x+55+(i/1.5), y+15-i, x+69-(i/1.5), y+15-i);
myGLCD.drawLine(x+3+(i/1.5), y+5+i, x+17-(i/1.5), y+5+i);}
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(x, y, x+20, y+20);
myGLCD.drawRoundRect(x+52, y, x+72, y+20);
}
void printButton(char* text, int x1, int y1, int x2, int y2, int fontsize = 0)
{
int stl = strlen(text);
int fx, fy;
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (x1, y1, x2, y2);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
myGLCD.setBackColor(0, 0, 255);
if (fontsize==0) {
myGLCD.setFont(BigFont);
fx = x1+(((x2 - x1+1)-(stl*16))/2);
fy = y1+(((y2 - y1+1)-16)/2);
myGLCD.print(text, fx, fy);
}
if (fontsize==1) {
myGLCD.setFont(SmallFont);
fx = x1+(((x2 - x1)-(stl*8))/2);
fy = y1+(((y2 - y1-1)-8)/2);
myGLCD.print(text, fx, fy);
}
}
void waitForIt(int x1, int y1, int x2, int y2) // Draw a red frame while a button is touched
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
waitForTouchRelease();
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
/**************************** END OF PRIMARY BUTTONS **********************************/
/********************************* EEPROM FUNCTIONS ***********************************/
struct config_t
{
int tempset;
int tempFset;
} tempSettings;
struct config_g
{
int HoodFanTempC;
int HoodFanTempF;
int SumpFanTempC;
int SumpFanTempF;
} GENERALsettings;
struct config_h
{
int on1;
int on2;
int on3;
int on4;
int on5;
int on6;
int on7;
int on8;
int on9;
int on10;
int on11;
int on12;
int off1;
int off2;
int off3;
int off4;
int off5;
int off6;
int off7;
int off8;
int off9;
int off10;
int off11;
int off12;
} TIMERsettings;
void SaveTempToEEPROM()
{
EEPROM.write(630, 115);
tempSettings.tempset = int(setTempC*10);
tempSettings.tempFset = int(setTempF*10);
EEPROM_writeAnything(632, tempSettings);
EEPROM.write(636, offTempC*10);
EEPROM.write(637, offTempF*10);
EEPROM.write(638, alarmTempC*10);
EEPROM.write(639, alarmTempF*10);
}
void SaveGenSetsToEEPROM()
{
EEPROM.write(640, 116);
EEPROM.write(641, setCalendarFormat);
EEPROM.write(642, displayDOW);
EEPROM.write(643, setTimeFormat);
EEPROM.write(644, setTempScale);
EEPROM_writeAnything(645, GENERALsettings);
EEPROM.write(653, setScreensaverOnOff);
EEPROM.write(654, setClockOrBlank);
EEPROM.write(655, setScreensaverDOWonOff);
EEPROM.write(656, setSSmintues);
}
void SaveTimerToEEPROM()
{
EEPROM.write(700, 119);
TIMERsettings.on1 = int(on1);
TIMERsettings.on2 = int(on2);
TIMERsettings.on3 = int(on3);
TIMERsettings.on4 = int(on4);
TIMERsettings.on5 = int(on5);
TIMERsettings.on6 = int(on6);
TIMERsettings.on7 = int(on7);
TIMERsettings.on8 = int(on8);
TIMERsettings.on9 = int(on9);
TIMERsettings.on10 = int(on10);
TIMERsettings.on11 = int(on11);
TIMERsettings.on12 = int(on12);
TIMERsettings.off1 = int(off1);
TIMERsettings.off2 = int(off2);
TIMERsettings.off3 = int(off3);
TIMERsettings.off4 = int(off4);
TIMERsettings.off5 = int(off5);
TIMERsettings.off6 = int(off6);
TIMERsettings.off7 = int(off7);
TIMERsettings.off8 = int(off8);
TIMERsettings.off9 = int(off9);
TIMERsettings.off10 = int(off10);
TIMERsettings.off11 = int(off11);
TIMERsettings.off12 = int(off12);
EEPROM_writeAnything(701, TIMERsettings);
}
void ReadFromEEPROM()
{
int k = EEPROM.read(630); delay(5);
if (k==115)
{EEPROM_readAnything(632, tempSettings);
setTempC = tempSettings.tempset;
setTempC /=10;
setTempF = tempSettings.tempFset;
setTempF /=10;
offTempC = EEPROM.read(636);
offTempC /=10;
offTempF = EEPROM.read(637);
offTempF /=10;
alarmTempC = EEPROM.read(638);
alarmTempC /= 10;
alarmTempF = EEPROM.read(639);
alarmTempF /= 10;}
setCalendarFormat = EEPROM.read(641);
displayDOW = EEPROM.read(642);
setTimeFormat = EEPROM.read(643);
setTempScale = EEPROM.read(644);
EEPROM_readAnything(645, GENERALsettings);
setScreensaverOnOff = EEPROM.read(653);
setClockOrBlank = EEPROM.read(654);
setScreensaverDOWonOff = EEPROM.read(655);
setSSmintues = EEPROM.read(656);
if (setSSmintues==0) {setSSmintues=20;}
k = EEPROM.read(700); delay(5);
if (k==119)
{EEPROM_readAnything(701, TIMERsettings);
on1 = TIMERsettings.on1;
on2 = TIMERsettings.on2;
on3 = TIMERsettings.on3;
on4 = TIMERsettings.on4;
on5 = TIMERsettings.on5;
on6 = TIMERsettings.on6;
on7 = TIMERsettings.on7;
on8 = TIMERsettings.on8;
on9 = TIMERsettings.on9;
on10 = TIMERsettings.on10;
on11 = TIMERsettings.on11;
on12 = TIMERsettings.on12;
off1 = TIMERsettings.off1;
off2 = TIMERsettings.off2;
off3 = TIMERsettings.off3;
off4 = TIMERsettings.off4;
off5 = TIMERsettings.off5;
off6 = TIMERsettings.off6;
off7 = TIMERsettings.off7;
off8 = TIMERsettings.off8;
off9 = TIMERsettings.off9;
off10 = TIMERsettings.off10;
off11 = TIMERsettings.off11;
off12 = TIMERsettings.off12;}
}
/***************************** END OF EEPROM FUNCTIONS ********************************/
/********************************** RTC FUNCTIONS *************************************/
void TimeDateBar(boolean refreshAll=false)
{
int Hour12;
String ampm;
t = rtc.getTime();
//Date
setFont(SMALL, 255, 255, 0, 64, 64, 64);
if ((setCalendarFormat==0) && (displayDOW==1))
{ myGLCD.print(" ", 48, 227);
myGLCD.print(rtc.getDateStr(FORMAT_LONG, FORMAT_LITTLEENDIAN, '/'), 56, 227);
myGLCD.print(" ", 136, 227);
t.dow=calcDOW(t.date, t.mon, t.year);
showDOWonBar(t.dow);}
if ((setCalendarFormat==1) && (displayDOW==1))
{ myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 56, 227); //3 letter Month
myGLCD.print(" ", 80, 227);
myGLCD.printNumI(t.date, 88, 227);
if (t.date<10)
{ myGLCD.print(", ", 96, 227);
myGLCD.printNumI(t.year, 112, 227);
myGLCD.print(" ", 144, 227);}
else
{ myGLCD.print(", ", 104, 227);
myGLCD.printNumI(t.year, 120, 227);
myGLCD.print(" ", 152, 227);}
t.dow=calcDOW(t.date, t.mon, t.year);
showDOWonBar(t.dow);}
if ((setCalendarFormat==0) && (displayDOW==0))
{ myGLCD.print(" ", 13, 227);
myGLCD.print(rtc.getDateStr(FORMAT_LONG, FORMAT_LITTLEENDIAN, '/'), 45, 227);
myGLCD.print(" ", 125, 227);}
if ((setCalendarFormat==1) && (displayDOW==0))
{ myGLCD.print(" ", 5, 227);
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 37, 227); //3 letter Month
myGLCD.print(" ", 61, 227);
myGLCD.printNumI(t.date, 69, 227);
if (t.date<10)
{ myGLCD.print(", ", 77, 227);
myGLCD.printNumI(t.year, 93, 227);
myGLCD.print(" ", 125, 227);}
else
{ myGLCD.print(", ", 85, 227);
myGLCD.printNumI(t.year, 101, 227);
myGLCD.print(" ", 133, 227);}
}
//Time
if (setTimeFormat==1)
{ if (t.hour==0) { Hour12 = 12; } //12 HR Format
else
{ if (t.hour>12) { Hour12 = t.hour-12; }
else { Hour12 = t.hour; }}
if (Hour12<10)
{ myGLCD.print(" ", 220, 227);
myGLCD.printNumI(Hour12, 228, 227);}
else
{ myGLCD.printNumI(Hour12, 220, 227);}
myGLCD.print(":", 236, 227);
if (t.min<10)
{ myGLCD.printNumI(0, 244, 227);
myGLCD.printNumI(t.min, 252, 227);}
else
{ myGLCD.printNumI(t.min, 244, 227);}
if(t.hour < 12){ myGLCD.print(" AM ", 260, 227); } //Adding the AM/PM sufffix
else { myGLCD.print(" PM ", 260, 227); }
}
else
{ myGLCD.print(rtc.getTimeStr(FORMAT_SHORT), 220, 227); //24 HR Format
myGLCD.print(" ", 260, 227);}
}
byte calcDOW(byte d, byte m, int y)
{
int dow;
byte mArr[12] = {6,2,2,5,0,3,5,1,4,6,2,4};
dow = (y % 100);
dow = dow*1.25;
dow += d;
dow += mArr[m-1];
if (((y % 4)==0) && (m<3))
dow -= 1;
while (dow>7)
dow -= 7;
return dow;
}
void showDOW(byte dow)
{
char* str[] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print(" ", 17, 178);
myGLCD.print(str[dow-1], 41, 178);
}
void showDOWonBar(byte dow)
{
char* str[] = {"MON,","TUE,","WED,","THU,","FRI,","SAT,","SUN,"};
myGLCD.print(str[dow-1], 16, 227);
}
byte validateDate(byte d, byte m, word y)
{
byte mArr[12] = {31,0,31,30,31,30,31,31,30,31,30,31};
byte od;
if (m==2)
{ if ((y % 4)==0)
{ if (d==30)
od=1;
else if (d==0)
od=29;
else
od=d;
}
else
{ if (d==29)
od=1;
else if (d==0)
od=28;
else
od=d;
}
}
else
{ if (d==0)
od=mArr[m-1];
else if (d==(mArr[m-1]+1))
od=1;
else
od=d;
}
return od;
}
byte validateDateForMonth(byte d, byte m, word y)
{
byte mArr[12] = {31,0,31,30,31,30,31,31,30,31,30,31};
byte od;
boolean dc=false;
if (m==2)
{ if ((y % 4)==0)
{ if (d>29)
{ d=29;}
}
else
{ if (d>28)
{ d=28;}
}
}
else
{ if (d>mArr[m-1])
{ d=mArr[m-1];}
}
return d;
}
/********************************* END OF RTC FUNCTIONS *******************************/
/******************************** TEMPERATURE FUNCTIONS *******************************/
void checkTempC()
{
sensors.requestTemperatures(); // call sensors.requestTemperatures() to issue a global
// temperature request to all devices on the bus
tempv1 = (sensors.getTempC(viv1Thermometer)); //read water temperature
tempv2 = (sensors.getTempC(viv2Thermometer)); //read water temperature
tempv3 = (sensors.getTempC(viv3Thermometer)); //read water temperature
tempv4 = (sensors.getTempC(viv4Thermometer)); //read water temperature
tempv5 = (sensors.getTempC(viv5Thermometer)); //read water temperature
tempv6 = (sensors.getTempC(viv6Thermometer)); //read water temperature
tempv7 = (sensors.getTempC(viv7Thermometer)); //read water temperature
tempv8 = (sensors.getTempC(viv8Thermometer)); //read water temperature
}
/*************************** END OF TEMPERATURE FUNCTIONS *****************************/
/********************************* MISC. FUNCTIONS ************************************/
void clearScreen()
{
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(1, 15, 318, 226);
}
void printHeader(char* headline)
{
setFont(SMALL, 255, 255, 0, 255, 255, 0);
myGLCD.fillRect (1, 1, 318, 14);
myGLCD.setColor(0, 0, 0);
myGLCD.print(headline, CENTER, 1);
}
void setFont(int font, byte cr, byte cg, byte cb, byte br, byte bg, byte bb)
{
myGLCD.setBackColor(br, bg, bb); //font background black
myGLCD.setColor(cr, cg, cb); //font color white
if (font==LARGE)
myGLCD.setFont(BigFont); //font size LARGE
if (font==SMALL)
myGLCD.setFont(SmallFont);
}
void waitForTouchRelease()
{
while (myTouch.dataAvailable()==true) //Wait for release
myTouch.read();
}
void TimeSaver(boolean refreshAll=false)
{
if (setTimeFormat==0) //24HR Format
{
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(SmallFont);
myGLCD.print(rtc.getTimeStr(FORMAT_SHORT), CENTER, 95);
}
if (setTimeFormat==1) //12HR Format
{
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(SmallFont);
if (t.hour==0) //Display HOUR
{ myGLCD.print("12", 61, 95);}
if ((t.hour>=1) && (t.hour<=9))
{ myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(61, 95, 92, 145);
myGLCD.setColor(0, 0, 255);
myGLCD.printNumI(t.hour, 93, 95);}
if ((t.hour>=10) && (t.hour<=12))
{ myGLCD.printNumI(t.hour, 61, 95);}
if ((t.hour>=13) && (t.hour<=21))
{ myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(61, 95, 92, 145);
myGLCD.setColor(0, 0, 255);
myGLCD.printNumI(t.hour-12, 93, 95);}
if (t.hour>=22)
{ myGLCD.printNumI(t.hour-12, 61, 95);}
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(SmallFont);
myGLCD.fillCircle(141, 108, 4);
myGLCD.fillCircle(141, 132, 4);
if ((t.min>=0) && (t.min<=9)) //Display MINUTES
{ myGLCD.print("0", 157, 95);
myGLCD.printNumI(t.min, 189, 95);}
else { myGLCD.printNumI(t.min, 157, 95);}
if ((t.hour>=0) && (t.hour<=11)) //Display AM/PM
{ setFont(LARGE, 0, 0, 255, 0, 0, 0);
myGLCD.print("AM", 225, 99);}
else
{ setFont(LARGE, 0, 0, 255, 0, 0, 0);
myGLCD.print("PM", 225, 99);}
}
if (setScreensaverDOWonOff==1) //Date and Date
{
t.dow=calcDOW(t.date, t.mon, t.year);
if (setTimeFormat==0)
{
SS_DOW_x=122;
showDOW_ScreenSaver(t.dow);
setFont(SMALL, 0, 0, 255, 0, 0, 0);
if (setCalendarFormat==0)
{
if (t.date<=9)
{ myGLCD.printNumI(t.date, 162, 157);
myGLCD.print(" ", 170, 157);
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 178, 157); //3 letter Month
myGLCD.print(" ", 202, 157);
}
else
{ myGLCD.printNumI(t.date, 162, 157);
myGLCD.print(" ", 178, 157);
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 186, 157);}
}
else
{
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 162, 157); //3 letter Month
myGLCD.printNumI(t.date, 194, 157);
if (t.date<=9) {myGLCD.print(" ", 202, 157);}
}
}
if (setTimeFormat==1)
{
if (((t.hour>=1)&&(t.hour<=9)) || ((t.hour>=13) && (t.hour<=21)))
{
myGLCD.print(" ", 105, 157);
SS_DOW_x=122;
showDOW_ScreenSaver(t.dow);
setFont(SMALL, 0, 0, 255, 0, 0, 0);
if (setCalendarFormat==0)
{
if (t.date<=9)
{ myGLCD.printNumI(t.date, 162, 157);
myGLCD.print(" ", 170, 157);
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 178, 157); //3 letter Month
myGLCD.print(" ", 202, 157);
}
else
{ myGLCD.printNumI(t.date, 162, 157);
myGLCD.print(" ", 178, 157);
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 186, 157);
myGLCD.print(" ", 210, 157);
}
}
else
{
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 162, 157); //3 letter Month
myGLCD.print(" ", 186, 157);
myGLCD.printNumI(t.date, 194, 157);
if (t.date<=9) {myGLCD.print(" ", 202, 157);}
}
}
else
{
SS_DOW_x=106;
showDOW_ScreenSaver(t.dow);
setFont(SMALL, 0, 0, 255, 0, 0, 0);
if (setCalendarFormat==0)
{
if (t.date<=9)
{ myGLCD.printNumI(t.date, 146, 157);
myGLCD.print(" ", 154, 157);
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 162, 157); //3 letter Month
myGLCD.print(" ", 186, 157);
}
else
{ myGLCD.printNumI(t.date, 146, 157);
myGLCD.print(" ", 162, 157);
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 170, 157);
myGLCD.print(" ", 194, 157);
}
}
else
{
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 146, 157); //3 letter Month
myGLCD.print(" ", 170, 157);
myGLCD.printNumI(t.date, 178, 157);
if (t.date<=9) {myGLCD.print(" ", 186, 157);}
myGLCD.print(" ", 194, 157);
}
}
}
}
}
void showDOW_ScreenSaver(byte dow)
{
char* str[] = {"MON, ","TUE, ","WED, ","THU, ","FRI, ","SAT, ","SUN, "};
setFont(SMALL, 0, 0, 255, 0, 0, 0);
myGLCD.print(str[dow-1], SS_DOW_x, 157);
}
void screenSaver() //Make the Screen Go Blank after so long
{
setScreenSaverTimer = setSSmintues * 12;
if ((setScreensaverOnOff==1) && (tempAlarmflag==false))
{
if (myTouch.dataAvailable())
{ processMyTouch();}
else { screenSaverCounter++;}
if (screenSaverCounter==setScreenSaverTimer)
{ dispScreen=0;
myGLCD.clrScr(); }
if (setClockOrBlank==0)
{ if (screenSaverCounter>setScreenSaverTimer)
{ dispScreen=0;
TimeSaver(true); }
}
}
}
void ScreensaverSelect()
{
if (setClockOrBlank==0) //Choose Screensaver Buttons
{ myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(185, 20, 235, 40);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("BLANK", 191, 24);
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(255, 20, 305, 40);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("CLOCK", 261, 24);
myGLCD.setColor(64, 64, 64);
myGLCD.drawLine(0, 76, 319, 76);
setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("Show Date w/ Clock", 25, 55);
}
else
{ myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(185, 20, 235, 40);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("BLANK", 191, 24);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(255, 20, 305, 40);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("CLOCK", 261, 24);
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(1, 47, 318, 77);
}
if (setClockOrBlank==0)
{
if (setScreensaverDOWonOff==0) //Show Date on Screensaver
{ myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(185, 51, 235, 71);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("YES", 198, 55);
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(255, 51, 305, 71);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("NO", 272, 55);
}
else
{ myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(185, 51, 235, 71);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("YES", 198, 55);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(255, 51, 305, 71);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("NO", 272, 55);
}
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(185, 51, 235, 71);
myGLCD.drawRoundRect(255, 51, 305, 71);
}
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(185, 20, 235, 40);
myGLCD.drawRoundRect(255, 20, 305, 40);
}
void genSetSelect_1()
{
if (setCalendarFormat==0) //Calendar Format Buttons
{ myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(185, 19, 305, 39);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("DD/MM/YYYY", 207, 23);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(185, 45, 305, 65);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("MTH DD, YYYY", 199, 49);
}
else
{ myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(185, 19, 305, 39);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("DD/MM/YYYY", 207, 23);
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(185, 45, 305, 65);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("MTH DD, YYYY", 199, 49);
}
if (displayDOW==1) //Show/Hide the Day of the Week
{ myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(195, 76, 235, 96);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("ON", 209, 80);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(255, 76, 295, 96);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("OFF", 265, 80);
}
else
{ myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(195, 76, 235, 96);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("ON", 209, 80);
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(255, 76, 295, 96);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("OFF", 265, 80);
}
if (setTimeFormat==0) //Time Format Buttons
{ myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(195, 107, 235, 127);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("12HR", 201, 111);
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(255, 107, 295, 127);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("24HR", 261, 111);
}
else
{ myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(195, 107, 235, 127);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("12HR", 201, 111);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(255, 107, 295, 127);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("24HR", 261, 111);
}
if (setTempScale==0) //Temperature Scale Buttons
{ myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(195, 138, 235, 158);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("C", 215, 142);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(255, 138, 295, 158);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("F", 275, 142);
myGLCD.setColor(0, 0, 0);
myGLCD.drawCircle(210, 144, 1);
myGLCD.setColor(255, 255, 255);
myGLCD.drawCircle(270, 144, 1);
}
else
{ myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(195, 138, 235, 158);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("C", 215, 142);
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(255, 138, 295, 158);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("F", 275, 142);
myGLCD.setColor(255, 255, 255);
myGLCD.drawCircle(210, 144, 1);
myGLCD.setColor(0, 0, 0);
myGLCD.drawCircle(270, 144, 1);
}
for (int x=0; x<2; x++)
{ for (int y=0; y<3; y++)
{ myGLCD.drawRoundRect((x*60)+195, (y*31)+76, (x*60)+235, (y*31)+96); }
}
}
void genSetSelect_2()
{
if (setScreensaverOnOff==1) //Screensaver Buttons
{ myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(195, 101, 235, 121);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("ON", 209, 105);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(255, 101, 295, 121);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("OFF", 265, 105);
}
else
{ myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(195, 101, 235, 121);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("ON", 209, 105);
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(255, 101, 295, 121);
setFont(SMALL, 0, 0, 0, 0, 255, 0);
myGLCD.print("OFF", 265, 105);
}
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(185, 129, 305, 149);
setFont(SMALL, 255, 255, 255, 0, 0, 255);
myGLCD.print("SETTINGS", 215, 133);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(195, 101, 235, 121);
myGLCD.drawRoundRect(255, 101, 295, 121);
myGLCD.drawRoundRect(185, 129, 305, 149);
}
/******************************* END OF MISC. FUNCTIONS *******************************/
/*********************** MAIN SCREEN ********** dispScreen = 0 ************************/
void mainScreen(boolean refreshAll=false)
{
int ledLevel, bar;
String oldval, deg;
TimeDateBar(true);
oldval = day; //refresh day if different
day = String(t.date);
if ((oldval!=day) || refreshAll)
{
myGLCD.setColor(25, 212, 218); //Draw Borders & Dividers in Grey
myGLCD.drawRect(0, 0, 319, 239); //Outside Border
myGLCD.drawRect(106, 14, 108, 226); //Vertical Divider
myGLCD.drawRect(212, 14, 214, 226); //Vertical Divider
myGLCD.drawRect(0, 78, 319, 80); //Horizontal Divider
myGLCD.drawRect(0, 158, 319, 160); //Horizontal Divider
myGLCD.fillRect(0, 0, 319, 14); //Top Bar
myGLCD.setColor(0, 0, 0);
// myGLCD.drawLine(159, 126, 161, 126); //Horizontal Divider Separator
setFont(SMALL, 64, 64, 64, 25, 212, 218);
myGLCD.print("VIVARIUM CONTROLR v2 AX2021", CENTER, 1);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Vivarium 1", 14, 20);
myGLCD.print("Vivarium 2", 122, 20);
myGLCD.print("Vivarium 3", 232, 20);
myGLCD.print("Vivarium 4", 14, 88);
myGLCD.print("Vivarium 5", 122, 88);
myGLCD.print("Vivarium 6", 232, 88);
myGLCD.print("Vivarium 7", 14, 164);
myGLCD.print("Vivarium 8", 122, 164);
myGLCD.print("Settings", 232, 164);
// setFont(SMALL, 255, 255, 255, 0, 0, 0);
// myGLCD.print("TIMER", 5, 146);
// for (int c=0; c<5; c++)
// { setFont(SMALL, 255, 255, 255, 0, 0, 0);
// myGLCD.printNumI(c+1, 7, (c*13)+158);
// myGLCD.setColor(64, 64, 64);
// myGLCD.drawRect(4, (c*13)+157, 42, (c*13)+170); }
}
// TimerStatusMainScreen();
/*****************************Temperature settings*************************/
if (setTempScale==1) {deg ="F";} //Print deg C or deg F
else {deg = "C";}
degC_F=deg;
char bufferDeg[2];
degC_F.toCharArray(bufferDeg,2);
if (refreshAll) //draw static elements
{
setFont(SMALL, 210, 210, 200, 0, 0 , 0);
myGLCD.print("Temp:", 5, 44); //temp1
myGLCD.drawCircle(86, 46, 1);
myGLCD.print(bufferDeg, 90, 44);
myGLCD.print("Temp:", 116, 44); //temp2
myGLCD.drawCircle(194, 46, 1);
myGLCD.print(bufferDeg, 198, 44);
myGLCD.print("Temp:", 222, 44); //temp3
myGLCD.drawCircle(303, 46, 1);
myGLCD.print(bufferDeg, 308, 44);
myGLCD.print("Temp:", 5, 112); //temp4
myGLCD.drawCircle(86, 114, 1);
myGLCD.print(bufferDeg, 90, 112);
myGLCD.print("Temp:", 116, 112); //temp5
myGLCD.drawCircle(194, 114, 1);
myGLCD.print(bufferDeg, 198, 112);
myGLCD.print("Temp:", 222, 112); //temp6
myGLCD.drawCircle(303, 114, 1);
myGLCD.print(bufferDeg, 308, 112);
myGLCD.print("Temp:", 5, 186); //temp7
myGLCD.drawCircle(86, 188, 1);
myGLCD.print(bufferDeg, 90, 186);
myGLCD.print("Temp:", 116, 186); //temp8
myGLCD.drawCircle(194, 188, 1);
myGLCD.print(bufferDeg, 198, 186);
}
if (tempv1<20) //range in deg C no matter what1
{setFont(SMALL, 93, 173, 226, 0, 0, 0);
myGLCD.print("Bulb", 42, 44);}
else {
if (setTempScale==1)
{tempv1 = ((tempv1*1.8) + 32.05);} //C to F with rounding
if (tempCoolflag==true) //Water temperature too HIGH
{setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.printNumF( tempv1, 1, 42, 44);}
else
{setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.printNumF( tempv1, 1, 42, 44);}
if ((tempv1<110) && (tempv1>=0))
{myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(131, 148, 139, 160);}}
if (tempv2<20) //range in deg C no matter what2
{setFont(SMALL, 93, 173, 226, 0, 0, 0);
myGLCD.print("Bulb", 152, 44);}
else {
if (setTempScale==1)
{tempv2 = ((tempv2*1.8) + 32.05);} //C to F with rounding
if (tempCoolflag==true) //Water temperature too HIGH
{setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.printNumF( tempv2, 1, 152, 34);}
else
{setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.printNumF( tempv2, 1, 152, 44);}
if ((tempv2<100) && (tempv2>=0))
{myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(292, 34, 300, 34);}}
if (tempv3<20) //range in deg C no matter what3
{setFont(SMALL, 93, 173, 226, 0, 0, 0);
myGLCD.print("Bulb", 258, 44);}
else {
if (setTempScale==1)
{tempv3 = ((tempv3*1.8) + 32.05);} //C to F with rounding
if (tempCoolflag==true) //Water temperature too HIGH
{setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.printNumF( tempv3, 1, 260, 44);}
else
{setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.printNumF( tempv3, 1, 260, 44);}
if ((tempv3<100) && (tempv3>=0))
{myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(131, 148, 139, 160);}}
if (tempv4<20) //range in deg C no matter what4
{setFont(SMALL, 93, 173, 226, 0, 0, 0);
myGLCD.print("Bulb", 45, 122);}
else {
if (setTempScale==1)
{tempv4 = ((tempv4*1.8) + 32.05);} //C to F with rounding
if (tempCoolflag==true) //Water temperature too HIGH
{setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.printNumF( tempv4, 1, 45, 112);}
else
{setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.printNumF( tempv4, 1, 45, 112);}
if ((tempv4<100) && (tempv4>=0))
{myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(292, 148, 300, 160);}}
if (tempv5<20) //range in deg C no matter what3
{setFont(SMALL, 93, 173, 226, 0, 0, 0);
myGLCD.print("Bulb", 156, 112);}
else {
if (setTempScale==1)
{tempv5 = ((tempv5*1.8) + 32.05);} //C to F with rounding
if (tempCoolflag==true) //Water temperature too HIGH
{setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.printNumF( tempv5, 1, 155, 112);}
else
{setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.printNumF( tempv5, 1, 155, 112);}
if ((tempv5<100) && (tempv5>=0))
{myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(131, 148, 139, 160);}}
if (tempv6<20) //range in deg C no matter what2
{setFont(SMALL, 93, 173, 226, 0, 0, 0);
myGLCD.print("Bulb", 258, 112);}
else {
if (setTempScale==1)
{tempv6 = ((tempv6*1.8) + 32.05);} //C to F with rounding
if (tempCoolflag==true) //Water temperature too HIGH
{setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.printNumF( tempv6, 1, 260, 112);}
else
{setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.printNumF( tempv6, 1, 260, 112);}
if ((tempv6<100) && (tempv6>=0))
{myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(292, 34, 300, 34);}}
if (tempv7<20) //range in deg C no matter what3
{setFont(SMALL, 93, 173, 226, 0, 0, 0);
myGLCD.print("Bulb", 44, 186);}
else {
if (setTempScale==1)
{tempv7 = ((tempv7*1.8) + 32.05);} //C to F with rounding
if (tempCoolflag==true) //Water temperature too HIGH
{setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.printNumF( tempv7, 1, 44, 186);}
else
{setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.printNumF( tempv7, 1, 44, 186);}
if ((tempv7<100) && (tempv7>=0))
{myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(131, 148, 139, 160);}}
if (tempv8<20) //range in deg C no matter what4
{setFont(SMALL, 93, 173, 226, 0, 0, 0);
myGLCD.print("Bulb", 154, 186);}
else {
if (setTempScale==1)
{tempv8 = ((tempv8*1.8) + 32.05);} //C to F with rounding
if (tempCoolflag==true) //temperature too HIGH
{setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.printNumF( tempv8, 1, 154, 186);}
else
{setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.printNumF( tempv8, 1, 154, 186);}
if ((tempv8<100) && (tempv8>=0))
{myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(292, 148, 300, 160);}}
}
/******************************** END OF MAIN SCREEN **********************************/
void screenReturn() //Auto Return to MainScreen()
{
setReturnTimer = setScreenSaverTimer * .75;
if (SCREEN_RETURN==true)
{
if (dispScreen!=0)
{
if (myTouch.dataAvailable())
{ processMyTouch();}
else { returnTimer++; }
if (returnTimer>setReturnTimer)
{
returnTimer=0;
ReadFromEEPROM();
dispScreen=0;
clearScreen();
mainScreen(true);
}
}
}
}
/*********************** MENU SCREEN ********** dispScreen = 1 ************************/
void menuScreen()
{
printHeader("Choose Option");
myGLCD.setColor(64, 64, 64);
myGLCD.drawRect(0, 196, 319, 194);
printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
printButton("Time and Date", tanD[0], tanD[1], tanD[2], tanD[3], SMALL);
printButton("H2O Temp Control", temC[0], temC[1], temC[2], temC[3], SMALL);
printButton("Manual control", wave[0], wave[1], wave[2], wave[3], SMALL);
printButton("General Settings", gSet[0], gSet[1], gSet[2], gSet[3], SMALL);
printButton("Timer Settings", TimerS[0], TimerS[1], TimerS[2], TimerS[3], SMALL);
printButton("About", about[0], about[1], about[2], about[3], SMALL);
}
/********************************* END OF MENU SCREEN *********************************/
/************** TIME and DATE SCREEN ********** dispScreen = 2 ************************/
void clockScreen(boolean refreshAll=true)
{
if (refreshAll)
{
rtcSetMin=t.min; rtcSetHr=t.hour;
rtcSetDy=t.date; rtcSetMon=t.mon; rtcSetYr=t.year;
printHeader("Time and Date Settings");
myGLCD.setColor(64, 64, 64); //Draw Dividers in Grey
myGLCD.drawRect(0, 196, 319, 194); //Bottom Horizontal Divider
myGLCD.drawLine(0, 104, 319, 104); //Middle Horizontal Divider
printButton("<< BACK", back[0], back[1], back[2], back[3], SMALL);
printButton("SAVE", prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3], SMALL);
printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
drawUpButton(houU[0], houU[1]); //hour up
drawUpButton(minU[0], minU[1]); //min up
drawDownButton(houD[0], houD[1]); //hour down
drawDownButton(minD[0], minD[1]); //min down
if (setTimeFormat==1)
{ drawUpButton(ampmU[0], ampmU[1]); //AM/PM up
drawDownButton(ampmD[0], ampmD[1]);} //AM/PM down
drawUpButton(dayU[0], dayU[1]); //day up
drawUpButton(monU[0], monU[1]); //month up
drawUpButton(yeaU[0], yeaU[1]); //year up
drawDownButton(dayD[0], dayD[1]); //day down
drawDownButton(monD[0], monD[1]); //month down
drawDownButton(yeaD[0], yeaD[1]); //year down
}
timeDispH=rtcSetHr; timeDispM=rtcSetMin;
xTimeH=107; yTime=52; xColon=xTimeH+42;
xTimeM10=xTimeH+70; xTimeM1=xTimeH+86; xTimeAMPM=xTimeH+155;
timeChange();
setFont(LARGE, 0, 0, 255, 0, 0, 0);
myGLCD.print("Date", 20, 142);
setFont(LARGE, 255, 255, 255, 0, 0, 0);
myGLCD.print("/", 149, 142);
myGLCD.print("/", 219, 142);
if (setCalendarFormat==0) //DD/MM/YYYY Format
{
setFont(SMALL, 0, 0, 255, 0, 0, 0);
myGLCD.print("(DD/MM/YYYY)", 5, 160);
setFont(LARGE, 255, 255, 255, 0, 0, 0);
if ((rtcSetDy>=0) && (rtcSetDy<=9)) //Set DAY
{ myGLCD.print("0", 107, 142);
myGLCD.printNumI(rtcSetDy, 123, 142);}
else { myGLCD.printNumI(rtcSetDy, 107, 142);}
if ((rtcSetMon>=0) && (rtcSetMon<=9)) //Set MONTH
{ myGLCD.print("0", 177, 142);
myGLCD.printNumI(rtcSetMon, 193, 142);}
else { myGLCD.printNumI(rtcSetMon, 177, 142);}
} else
if (setCalendarFormat==1) //MM/DD/YYYY Format
{
setFont(SMALL, 0, 0, 255, 0, 0, 0);
myGLCD.print("(MM/DD/YYYY)", 5, 160);
setFont(LARGE, 255, 255, 255, 0, 0, 0);
if ((rtcSetMon>=0) && (rtcSetMon<=9)) //Set MONTH
{ myGLCD.print("0", 107, 142);
myGLCD.printNumI(rtcSetMon, 123, 142);}
else { myGLCD.printNumI(rtcSetMon, 107, 142);}
if ((rtcSetDy>=0) && (rtcSetDy<=9)) //Set DAY
{ myGLCD.print("0", 177, 142);
myGLCD.printNumI(rtcSetDy, 193, 142);}
else { myGLCD.printNumI(rtcSetDy, 177, 142);}
}
myGLCD.printNumI(rtcSetYr, 247, 142); //Set YEAR
}
void timeChange()
{
setFont(LARGE, 0, 0, 255, 0, 0, 0);
myGLCD.print("Time", 20, yTime);
if (setTimeFormat==0) //24HR Format
{ setFont(SMALL, 0, 0, 255, 0, 0, 0);
myGLCD.print("(24HR)", 29, yTime+18);}
if (setTimeFormat==1) //12HR Format
{ setFont(SMALL, 0, 0, 255, 0, 0, 0);
myGLCD.print("(12HR)", 29, yTime+18);}
timeCorrectFormat();
}
void timeCorrectFormat()
{
setFont(LARGE, 255, 255, 255, 0, 0, 0);
myGLCD.print(":", xColon, yTime);
if (setTimeFormat==0) //24HR Format
{
setFont(LARGE, 255, 255, 255, 0, 0, 0);
if ((timeDispH>=0) && (timeDispH<=9)) //Set HOUR
{ myGLCD.print("0", xTimeH, yTime);
myGLCD.printNumI(timeDispH, xTimeH+16, yTime);}
else { myGLCD.printNumI(timeDispH, xTimeH, yTime);}
}
if (setTimeFormat==1) //12HR Format
{
setFont(LARGE, 255, 255, 255, 0, 0, 0);
if (timeDispH==0) //Set HOUR
{ myGLCD.print("12", xTimeH, yTime);}
if ((timeDispH>=1) && (timeDispH<=9))
{ myGLCD.print("0", xTimeH, yTime);
myGLCD.printNumI(timeDispH, xTimeH+16, yTime);}
if ((timeDispH>=10) && (timeDispH<=12))
{ myGLCD.printNumI(timeDispH, xTimeH, yTime);}
if ((timeDispH>=13) && (timeDispH<=21))
{ myGLCD.print("0", xTimeH, yTime);
myGLCD.printNumI(timeDispH-12, xTimeH+16, yTime);}
if (timeDispH>=22)
{ myGLCD.printNumI(timeDispH-12, xTimeH, yTime);}
if (AM_PM==1)
{ myGLCD.print("AM", xTimeAMPM, yTime); }
if (AM_PM==2)
{ myGLCD.print("PM", xTimeAMPM, yTime); }
}
if ((timeDispM>=0) && (timeDispM<=9)) //Set MINUTES
{ myGLCD.print("0", xTimeM10, yTime);
myGLCD.printNumI(timeDispM, xTimeM1, yTime);}
else { myGLCD.printNumI(timeDispM, xTimeM10, yTime);}
}
/**************************** END OF TIME and DATE SCREEN *****************************/
/*********** H2O TEMP CONTROL SCREEN ********** dispScreen = 3 ************************/
void tempScreen(boolean refreshAll=false)
{
String deg;
if (refreshAll)
{
if ((setTempC==0) && (setTempScale==0)) {
setTempC = 26.1; } //change to 26.1 deg C
if (((setTempF==0) || (setTempF==setTempC)) && (setTempScale==1)) {
setTempF = 79.0; } //change to 79.0 deg F
if (setTempScale==1) {
temp2beS = setTempF;
temp2beO = offTempF;
temp2beA = alarmTempF; }
else {
temp2beS = setTempC;
temp2beO = offTempC;
temp2beA = alarmTempC; }
printHeader("H2O Temperature Control Settings");
myGLCD.setColor(64, 64, 64); //Draw Dividers in Grey
myGLCD.drawRect(0, 196, 319, 194); //Bottom Horizontal Divider
printButton("<< BACK", back[0], back[1], back[2], back[3], SMALL);
printButton("SAVE", prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3], SMALL);
printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
if (setTempScale==1) {deg ="F";} //Print deg C or deg F
else {deg = "C";}
degC_F=deg;
char bufferDeg[2];
degC_F.toCharArray(bufferDeg,2);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Desired Temperature in", 60, 34);
myGLCD.drawCircle(245, 36, 1);
myGLCD.print(bufferDeg, 250, 34);
myGLCD.print(":",258,34);
myGLCD.print("Temperature Offset:", CENTER, 84);
myGLCD.print("Alarm Offset:", CENTER, 134);
printButton("-", temM[0], temM[1], temM[2], temM[3], LARGE); //temp minus
printButton("+", temP[0], temP[1], temP[2], temP[3], LARGE); //temp plus
printButton("-", offM[0], offM[1], offM[2], offM[3], LARGE); //offset minus
printButton("+", offP[0], offP[1], offP[2], offP[3], LARGE); //offset plus
printButton("-", almM[0], almM[1], almM[2], almM[3], LARGE); //alarm minus
printButton("+", almP[0], almP[1], almP[2], almP[3], LARGE); //alarm plus
}
setFont(LARGE, 255, 255, 255, 0, 0, 0);
myGLCD.printNumF(temp2beS, 1, CENTER, 54);
myGLCD.printNumF(temp2beO, 1, CENTER, 104);
myGLCD.printNumF(temp2beA, 1, CENTER, 154);
}
/************************** END of H20 TEMP CONTROL SCREEN ****************************/
/******* GENERAL SETTINGS PG1 SCREEN ************ dispScreen = 14 *********************/
void generalSettingsScreen_1()
{
printHeader("View/Change General Settings: Page 1");
myGLCD.setColor(64, 64, 64);
myGLCD.drawRect(0, 196, 319, 194);
for (int y=0; y<4; y++)
{ myGLCD.drawLine(0, (y*31)+70, 319, (y*31)+70); }
printButton("<< BACK", backGS[0], backGS[1], backGS[2], backGS[3], SMALL);
printButton("NEXT >>", nextGS[0], nextGS[1], nextGS[2], nextGS[3], SMALL);
printButton("SAVE", prSAVEgs[0], prSAVEgs[1], prSAVEgs[2], prSAVEgs[3], SMALL);
printButton("CANCEL", canCgs[0], canCgs[1], canCgs[2], canCgs[3], SMALL);
setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("Calendar Format", 25, 36);
myGLCD.print("Show Day of Week", 25, 80);
myGLCD.print("Time Format", 25, 111);
myGLCD.print("Temperature Scale", 25, 142);
//myGLCD.print("Fan Startup Temps", 25, 173);
genSetSelect_1();
}
/************************ END OF GENERAL SETTINGS PAGE 1 SCREEN ***********************/
/******* GENERAL SETTINGS PG2 SCREEN ************ dispScreen = 15 *********************/
void generalSettingsScreen_2()
{
printHeader("View/Change General Settings: Page 2");
myGLCD.setColor(64, 64, 64);
myGLCD.drawLine(0, 88, 319, 88);
myGLCD.drawLine(0, 162, 319, 162);
myGLCD.drawRect(0, 196, 319, 194);
printButton("<< BACK", backGS[0], backGS[1], backGS[2], backGS[3], SMALL);
printButton("SAVE", prSAVEgs[0], prSAVEgs[1], prSAVEgs[2], prSAVEgs[3], SMALL);
printButton("CANCEL", canCgs[0], canCgs[1], canCgs[2], canCgs[3], SMALL);
setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("Screensaver", 25, 119);
genSetSelect_2();
}
/************************ END OF GENERAL SETTINGS PAGE 2 SCREEN ***********************/
/***** SET SCREENSAVER WAIT TIME SCREEN ********** dispScreen = 19 ********************/
void ScreensaverSettingsScreen()
{
printHeader("View/Change Screensaver Settings");
myGLCD.setColor(64, 64, 64);
myGLCD.drawLine(0, 45, 319, 45);
setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("Choose Screensaver", 25, 24);
myGLCD.print("Wait:", 67, 130);
myGLCD.print("minutes", 213, 130);
myGLCD.setColor(64, 64, 64);
myGLCD.drawRoundRect(115, 102, 205,167);
drawUpButton(175, 107);
drawDownButton(175, 137);
setFont(LARGE, 0, 255, 0, 0, 0, 0);
TempSSminutes=setSSmintues;
if (TempSSminutes>=10)
{ myGLCD.printNumI(TempSSminutes, 129, 126);}
else { myGLCD.printNumI(TempSSminutes, 137, 126);}
myGLCD.setColor(64, 64, 64);
myGLCD.drawRect(0, 196, 319, 194);
printButton("<< BACK", back[0], back[1], back[2], back[3], SMALL);
printButton("SAVE", prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3], SMALL);
printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
ScreensaverSelect();
}
/********************** END OF SET SCREENSAVER WAIT TIME SCREEN ***********************/
/************** ABOUT SCREEN ****************** dispScreen = 20 ***********************/
void AboutScreen()
{
printHeader("Vivarium Controller v.1.20");
setFont(SMALL, 0, 255, 0, 0, 0 , 0);
myGLCD.print("BETA Release Date: May 2012", CENTER, 20);
myGLCD.print("Written by Jamie Jardin", CENTER, 32);
myGLCD.print("Main code based on Stilo", 5, 52);
myGLCD.print("http://code.google.com/p/stilo/", 5, 64);
myGLCD.print("LED controlling algorithm based on", 5, 84);
myGLCD.print("Krusduino by Hugh Dangerfield", 5, 96);
myGLCD.print("and Dave Rosser", 5, 108);
myGLCD.print("http://code.google.com/p/dangerduino/", 5, 120);
myGLCD.print("Special Thanks: Hugh & Dave, Kev Tench,", 5, 140);
myGLCD.print("Mark Chester, Ned Simpson, Stilo, Neil", 5, 152);
myGLCD.print("Williams, my Dad, and my loving Wife", 5, 164);
myGLCD.print("Modefied for Vivarium by TelB", 5, 176);
myGLCD.setColor(64, 64, 64);
myGLCD.drawRect(0, 196, 319, 194);
printButton("<< BACK", back[0], back[1], back[2], back[3], SMALL);
printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
}
/********************************* END OF ABOUT SCREEN ********************************/
/************** TIMER SCREEN ****************** dispScreen = 22 ***********************/
void TimerScreen()
{
printHeader("View/Change Timer Settings");
myGLCD.setColor(64, 64, 64);
for (int x=0; x<6; x++)
for (int x=0; x<6; x++)
{ myGLCD.setColor(0, 0, 255);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect((x*50)+4, 39, (x*50)+52, 107); //Frames
myGLCD.drawRoundRect((x*50)+5, 38, (x*50)+52, 108);
}
for (int x=0; x<6; x++)
{ for (int y=0; y<2; y++)
{ if (y==0) {myGLCD.setColor(0, 255, 0);}
else {myGLCD.setColor(255, 0, 0);}
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect((x*50)+4, (y*34)+57, (x*50)+52, (y*36)+70); //Time Boxes
}
}
for (int x=0; x<6; x++)
{ setFont(LARGE, 255, 255, 255, 0, 255, 0);
myGLCD.print(" ON", (x*50)+5, 40);
setFont(LARGE, 255, 255, 255, 255, 0, 0);
myGLCD.print("OFF",(x*50)+5, 75);
}
for (int x=0; x<6; x++)
{ myGLCD.setColor(0, 0, 255);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect((x*50)+4, 119, (x*50)+52, 197); //Frames
myGLCD.drawRoundRect((x*50)+5, 118, (x*50)+53, 198);
}
for (int x=0; x<6; x++)
{ for (int y=0; y<2; y++)
{ if (y==0) {myGLCD.setColor(0, 255, 0);}
else {myGLCD.setColor(255, 0, 0);}
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect((x*50)+4, (y*41)+156, (x*50)+52, (y*42)+138); //Time Boxes
}
}
for (int x=0; x<6; x++)
{ setFont(LARGE, 255, 255, 255, 0, 255, 0);
myGLCD.print(" ON", (x*50)+5, 120);
setFont(LARGE, 255, 255, 255, 255, 0, 0);
myGLCD.print("OFF",(x*50)+5, 160);
}
setFont(SMALL, 255, 255, 255, 0, 0, 0);
// if (setTimeFormat==1) ***************************************** ADD 12 HR FORMAT!!!!!!
for (int i=0; i<6; i++) //Relay ON Times
{ if (i==0) { ONtime=on1;}
if (i==1) { ONtime=on2;}
if (i==2) { ONtime=on3;}
if (i==3) { ONtime=on4;}
if (i==4) { ONtime=on5;}
if (i==5) { ONtime=on6;}
if (ONtime/60<10) //Display Hours
{ myGLCD.print("0", (i*50)+14, 58);
myGLCD.printNumI(ONtime/60, (i*50)+22, 58);}
else
{ myGLCD.printNumI(ONtime/60, (i*50)+14, 58);}
myGLCD.print(":", (i*50)+29, 58);
if (ONtime-((ONtime/60)*60)<10) //Display Minutes
{ myGLCD.print("0", (i*50)+36, 58);
myGLCD.printNumI(ONtime-((ONtime/60)*60), (i*50)+44, 58);
}
else
{ myGLCD.printNumI(ONtime-((ONtime/60)*60), (i*50)+36, 58);}
}
for (int i=0; i<6; i++) //Relay OFF Times
{ if (i==0) { OFFtime=off1;}
if (i==1) { OFFtime=off2;}
if (i==2) { OFFtime=off3;}
if (i==3) { OFFtime=off4;}
if (i==4) { OFFtime=off5;}
if (i==5) { OFFtime=off6;}
if (OFFtime/60<10) //Display Hours
{ myGLCD.print("0", (i*50)+14, 92);
myGLCD.printNumI(OFFtime/60, (i*50)+22, 92);}
else
{ myGLCD.printNumI(OFFtime/60, (i*50)+14, 92);}
myGLCD.print(":", (i*50)+29, 92);
if (OFFtime-((OFFtime/60)*60)<10) //Display Minutes
{ myGLCD.print("0", (i*50)+36, 92);
myGLCD.printNumI(OFFtime-((OFFtime/60)*60), (i*50)+44, 92);
}
else
{ myGLCD.printNumI(OFFtime-((OFFtime/60)*60), (i*50)+36, 92);}
}
for (int i=6; i<12; i++) //Relay ON Times
{ if (i==6) { ONtime=on7;}
if (i==7) { ONtime=on8;}
if (i==8) { ONtime=on9;}
if (i==9) { ONtime=on10;}
if (i==10) { ONtime=on11;}
if (i==11) { ONtime=on12;}
if (ONtime/60<10) //Display Hours
{ myGLCD.print("0", (i*50)+220, 140);
myGLCD.printNumI(ONtime/60, (i*50)+228, 140);}
else
{ myGLCD.printNumI(ONtime/60, (i*50)+220, 140);}
myGLCD.print(":", (i*50)+236, 140);
if (ONtime-((ONtime/60)*60)<10) //Display Minutes
{ myGLCD.print("0", (i*50)+244, 140);
myGLCD.printNumI(ONtime-((ONtime/60)*60), (i*50)+252, 140);
}
else
{ myGLCD.printNumI(ONtime-((ONtime/60)*60), (i*50)+244, 140);}
}
for (int i=6; i<12; i++) //Relay OFF Times
{ if (i==6) { OFFtime=off7;}
if (i==7) { OFFtime=off8;}
if (i==8) { OFFtime=off9;}
if (i==9) { OFFtime=off10;}
if (i==10) { OFFtime=off11;}
if (i==11) { OFFtime=off12;}
if (OFFtime/60<10) //Display Hours
{ myGLCD.print("0", (i*50)+220, 182);
myGLCD.printNumI(OFFtime/60, (i*50)+228, 182);}
else
{ myGLCD.printNumI(OFFtime/60, (i*50)+220, 182);}
myGLCD.print(":", (i*50)+236, 182);
if (OFFtime-((OFFtime/60)*60)<10) //Display Minutes
{ myGLCD.print("0", (i*50)+244, 182);
myGLCD.printNumI(OFFtime-((OFFtime/60)*60), (i*50)+252, 182);
}
else
{ myGLCD.printNumI(OFFtime-((OFFtime/60)*60), (i*50)+244, 182);}
}
myGLCD.setColor(64, 64, 64);
myGLCD.drawRect(0, 196, 319, 194);
printButton("<< BACK", back[0], back[1], back[2], back[3], SMALL);
if (timerPage==0)
{ printButton("CONTROL", prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3], SMALL);}
printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
}
void RelaySetTimesPage() /*********************************** dispScreen = 23 *********/
{
printHeader("Set Relay ON/OFF Times");
myGLCD.printNumI(slctRelay, 144,1 );
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(20, 38, 84, 81); //ON Label
myGLCD.setColor(255, 0, 0);
myGLCD.fillRoundRect(20, 128, 84, 171); //OFF Label
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(20, 38, 84, 81);
myGLCD.drawRoundRect(20, 128, 84, 171);
setFont(LARGE, 0, 0, 0, 0, 255, 0);
myGLCD.print("ON", 36, 52);
setFont(LARGE, 0, 0, 0, 255, 0, 0);
myGLCD.print("OFF", 28, 142);
setFont(LARGE, 255, 255, 255, 0, 0, 0);
myGLCD.print(":", 149, 52);
myGLCD.print(":", 149, 142);
drawUpButton(houU[0], houU[1]); //ON - hour up
drawUpButton(minU[0], minU[1]); //ON - min up
drawDownButton(houD[0], houD[1]); //ON - hour down
drawDownButton(minD[0], minD[1]); //ON - min down
if (setTimeFormat==1)
{ drawUpButton(ampmU[0], ampmU[1]); //ON - AM/PM up
drawDownButton(ampmD[0], ampmD[1]); //ON - AM/PM down
drawUpButton(yeaU[0], yeaU[1]); //OFF - AM/PM up
drawDownButton(yeaD[0], yeaD[1]); //OFF - AM/PM down
}
drawUpButton(dayU[0], dayU[1]); //OFF - hour up
drawUpButton(monU[0], monU[1]); //OFF - min up
drawDownButton(dayD[0], dayD[1]); //OFF - hour down
drawDownButton(monD[0], monD[1]); //OFF - min down
RelaySetTimes();
myGLCD.setColor(64, 64, 64); //Draw Dividers in Grey
myGLCD.drawRect(0, 196, 319, 194); //Bottom Horizontal Divider
myGLCD.drawLine(0, 104, 319, 104); //Middle Horizontal Divider
printButton("<< BACK", back[0], back[1], back[2], back[3], SMALL);
printButton("SAVE", prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3], SMALL);
printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
}
void RelaySetTimes()
{
setFont(LARGE, 255, 255, 255, 0, 0, 0);
if (slctONtm<0){slctONtm=1439;} //Button +
if (slctONtm>1439){slctONtm=0;}
if (slctOFFtm<0){slctOFFtm=1439;} //Button -
if (slctOFFtm>1439){slctOFFtm=0;}
if (slctONtm/60<10) //ON - HRS
{ myGLCD.print("0", 107, 52);
myGLCD.printNumI(slctONtm/60, 123, 52);}
else { myGLCD.printNumI(slctONtm/60, 107, 52);}
if (slctONtm-((slctONtm/60)*60)<10) //ON - MINS
{ myGLCD.print("0", 178, 52);
myGLCD.printNumI(slctONtm-((slctONtm/60)*60), 194, 52);}
else { myGLCD.printNumI(slctONtm-((slctONtm/60)*60), 178, 52);}
if (slctOFFtm/60<10) //OFF - HRS
{ myGLCD.print("0", 107, 142);
myGLCD.printNumI(slctOFFtm/60, 123, 142);}
else { myGLCD.printNumI(slctOFFtm/60, 107, 142);}
if (slctOFFtm-((slctOFFtm/60)*60)<10) //OFF - MINS
{ myGLCD.print("0", 178, 142);
myGLCD.printNumI(slctOFFtm-((slctOFFtm/60)*60), 194, 142);}
else { myGLCD.printNumI(slctOFFtm-((slctOFFtm/60)*60), 178, 142);}
}
void RelayStatus()
{
if (timer1Status<2)
{ if (on1<off1){if (min_cnt>=on1 && min_cnt<off1){timer1Status=1;} else {timer1Status=0;}}
if (on1>off1){if (min_cnt<on1 && min_cnt>=off1){timer1Status=0;} else {timer1Status=1;}}}
if (timer2Status<2)
{ if (on2<off2){if (min_cnt>=on2 && min_cnt<off2){timer2Status=1;} else {timer2Status=0;}}
if (on2>off2){if (min_cnt<on2 && min_cnt>=off2){timer2Status=0;} else {timer2Status=1;}}}
if (timer3Status<2)
{ if (on3<off3){if (min_cnt>=on3 && min_cnt<off3){timer3Status=1;} else {timer3Status=0;}}
if (on3>off3){if (min_cnt<on3 && min_cnt>=off3){timer3Status=0;} else {timer3Status=1;}}}
if (timer4Status<2)
{ if (on4<off4){if (min_cnt>=on4 && min_cnt<off4){timer4Status=1;} else {timer4Status=0;}}
if (on4>off4){if (min_cnt<on4 && min_cnt>=off4){timer4Status=0;} else {timer4Status=1;}}}
if (timer5Status<2)
{ if (on5<off5){if (min_cnt>=on5 && min_cnt<off5){timer5Status=1;} else {timer5Status=0;}}
if (on5>off5){if (min_cnt<on5 && min_cnt>=off5){timer5Status=0;} else {timer5Status=1;}}}
if (timer6Status<2)
{ if (on6<off6){if (min_cnt>=on6 && min_cnt<off6){timer6Status=1;} else {timer6Status=0;}}
if (on6>off6){if (min_cnt<on6 && min_cnt>=off6){timer6Status=0;} else {timer6Status=1;}}}
if (timer7Status<2)
{ if (on7<off7){if (min_cnt>=on7 && min_cnt<off7){timer7Status=1;} else {timer7Status=0;}}
if (on7>off7){if (min_cnt<on7 && min_cnt>=off7){timer7Status=0;} else {timer7Status=1;}}}
if (timer8Status<2)
{ if (on8<off8){if (min_cnt>=on8 && min_cnt<off8){timer8Status=1;} else {timer8Status=0;}}
if (on8>off8){if (min_cnt<on8 && min_cnt>=off8){timer8Status=0;} else {timer8Status=1;}}}
if (timer9Status<2)
{ if (on9<off9){if (min_cnt>=on9 && min_cnt<off9){timer9Status=1;} else {timer9Status=0;}}
if (on9>off9){if (min_cnt<on9 && min_cnt>=off9){timer9Status=0;} else {timer9Status=1;}}}
if (timer10Status<2)
{ if (on10<off10){if (min_cnt>=on10 && min_cnt<off10){timer10Status=1;} else {timer10Status=0;}}
if (on10>off10){if (min_cnt<on10 && min_cnt>=off10){timer10Status=0;} else {timer10Status=1;}}}
if (timer11Status<2)
{ if (on11<off11){if (min_cnt>=on11 && min_cnt<off11){timer11Status=1;} else {timer11Status=0;}}
if (on11>off11){if (min_cnt<on11 && min_cnt>=off11){timer11Status=0;} else {timer11Status=1;}}}
if (timer12Status<2)
{ if (on12<off12){if (min_cnt>=on12 && min_cnt<off12){timer12Status=1;} else {timer12Status=0;}}
if (on12>off12){if (min_cnt<on12 && min_cnt>=off12){timer12Status=0;} else {timer12Status=1;}}}
//Port Management 0-auto off, 1-AUTO ON/OFF, 2-ON, 3-OFF
if (timer1Status==0){digitalWrite(timer1, LOW);} //Auto OFF
if (timer1Status==1){digitalWrite(timer1, HIGH);} //Auto ON
if (timer1Status==2){digitalWrite(timer1, HIGH);} //ON
if (timer1Status==3){digitalWrite(timer1, LOW);} //OFF
if (timer2Status==0){digitalWrite(timer2, LOW);} //Auto OFF
if (timer2Status==1){digitalWrite(timer2, HIGH);} //Auto ON
if (timer2Status==2){digitalWrite(timer2, HIGH);} //ON
if (timer2Status==3){digitalWrite(timer2, LOW);} //OFF
if (timer3Status==0){digitalWrite(timer3, LOW);} //Auto OFF
if (timer3Status==1){digitalWrite(timer3, HIGH);} //Auto ON
if (timer3Status==2){digitalWrite(timer3, HIGH);} //ON
if (timer3Status==3){digitalWrite(timer3, LOW);} //OFF
if (timer4Status==0){digitalWrite(timer4, LOW);} //Auto OFF
if (timer4Status==1){digitalWrite(timer4, HIGH);} //Auto ON
if (timer4Status==2){digitalWrite(timer4, HIGH);} //ON
if (timer4Status==3){digitalWrite(timer4, LOW);} //OFF
if (timer5Status==0){digitalWrite(timer5, LOW);} //Auto OFF
if (timer5Status==1){digitalWrite(timer5, HIGH);} //Auto ON
if (timer5Status==2){digitalWrite(timer5, HIGH);} //ON
if (timer5Status==3){digitalWrite(timer5, LOW);} //OFF
if (timer6Status==0){digitalWrite(timer6, LOW);} //Auto OFF
if (timer6Status==1){digitalWrite(timer6, HIGH);} //Auto ON
if (timer6Status==2){digitalWrite(timer6, HIGH);} //ON
if (timer6Status==3){digitalWrite(timer6, LOW);} //OFF
if (timer7Status==0){digitalWrite(timer7, LOW);} //Auto OFF
if (timer7Status==1){digitalWrite(timer7, HIGH);} //Auto ON
if (timer7Status==2){digitalWrite(timer7, HIGH);} //ON
if (timer7Status==3){digitalWrite(timer7, LOW);} //OFF
if (timer8Status==0){digitalWrite(timer8, LOW);} //Auto OFF
if (timer8Status==1){digitalWrite(timer8, HIGH);} //Auto ON
if (timer8Status==2){digitalWrite(timer8, HIGH);} //ON
if (timer8Status==3){digitalWrite(timer8, LOW);} //OFF
if (timer9Status==0){digitalWrite(timer9, LOW);} //Auto OFF
if (timer9Status==1){digitalWrite(timer9, HIGH);} //Auto ON
if (timer9Status==2){digitalWrite(timer9, HIGH);} //ON
if (timer9Status==3){digitalWrite(timer9, LOW);} //OFF
if (timer10Status==0){digitalWrite(timer10, LOW);} //Auto OFF
if (timer10Status==1){digitalWrite(timer10, HIGH);} //Auto ON
if (timer10Status==2){digitalWrite(timer10, HIGH);} //ON
if (timer10Status==3){digitalWrite(timer10, LOW);} //OFF
if (timer11Status==0){digitalWrite(timer11, LOW);} //Auto OFF
if (timer11Status==1){digitalWrite(timer11, HIGH);} //Auto ON
if (timer11Status==2){digitalWrite(timer11, HIGH);} //ON
if (timer11Status==3){digitalWrite(timer11, LOW);} //OFF
if (timer12Status==0){digitalWrite(timer12, LOW);} //Auto OFF
if (timer12Status==1){digitalWrite(timer12, HIGH);} //Auto ON
if (timer12Status==2){digitalWrite(timer12, HIGH);} //ON
if (timer12Status==3){digitalWrite(timer12, LOW);} //OFF
}
void graphonoff() /****** MANUAL CONTROL SCREEN ************* dispScreen = 24 *********/
{
printHeader("Manual Control");
myGLCD.setColor(64, 64, 64); // color gray
for (int i=0; i<6; i++)
{ for (int j=0; j<3; j++)
{ myGLCD.drawRect(0, (i*29)+20, 24, (i*29)+40);
myGLCD.drawRect((j*36)+28, (i*29)+20, (j*36)+62, (i*29)+40);}
}
myGLCD.setColor(64, 64, 64); // color gray
for (int i=0; i<6; i++)
{ for (int j=0; j<3; j++)
{ myGLCD.drawRect(150, (i*29)+20, 190, (i*29)+40);
myGLCD.drawRect((j*36)+192, (i*29)+20, (j*36)+226, (i*29)+40);}
}
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("T1", 3, 25);
myGLCD.print("T2", 3, 53);
myGLCD.print("T3", 3, 82);
myGLCD.print("T4", 3, 110);
myGLCD.print("T5", 3, 140);
myGLCD.print("T6", 3, 169);
myGLCD.print("T7", 160, 25);
myGLCD.print("T8", 160, 53);
myGLCD.print("T9", 160, 82);
myGLCD.print("T10", 160, 110);
myGLCD.print("T11", 160, 140);
myGLCD.print("T12", 160, 169);
OnOffAuto();
printButton("<< BACK", back[0], back[1], back[2], back[3], SMALL);
if (timerPage==1)
{ printButton("TIMERS", prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3], SMALL);}
printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
}
void OnOffAuto()
{
int timerStatus;
myGLCD.setFont(SmallFont);
myGLCD.setBackColor(0, 0, 0);
for (int i=0; i<6; i++)
{ if (i==0) { timerStatus=timer1Status;}
if (i==1) { timerStatus=timer2Status;}
if (i==2) { timerStatus=timer3Status;}
if (i==3) { timerStatus=timer4Status;}
if (i==4) { timerStatus=timer5Status;}
if (i==5) { timerStatus=timer6Status;}
if (timerStatus==0) //AUTO OFF (purple)
{ myGLCD.setColor(147, 115, 255);
myGLCD.print("AUTO", 30, (i*29)+25);
myGLCD.drawRect(27, (i*29)+20, 63, (i*29)+40);
myGLCD.setColor(80, 80, 80); //dark gray
myGLCD.print("OFF", 70, (i*29)+25);
myGLCD.print("ON", 112, (i*29)+25);
myGLCD.setColor(190, 190, 190); //light gray
myGLCD.drawRect(66, (i*29)+20, 98, (i*29)+40); //ON BOX
myGLCD.drawRect(102, (i*29)+20, 134, (i*29)+40); //OFF BOX
}
if (timerStatus==1) //AUTO ON (dark green)
{ myGLCD.setColor(0, 100, 0);
myGLCD.print("AUTO", 30, (i*29)+25);
myGLCD.drawRect(27, (i*29)+20, 63, (i*29)+40);
myGLCD.setColor(80, 80, 80); //dark gray
myGLCD.print("OFF", 70, (i*29)+25);
myGLCD.print("ON", 112, (i*29)+25);
myGLCD.setColor(190, 190, 190); //light gray
myGLCD.drawRect(66, (i*29)+20, 98, (i*29)+40); //ON BOX
myGLCD.drawRect(102, (i*29)+20, 134, (i*29)+40); //OFF BOX
}
if (timerStatus==2) //MANUAL ON (green)
{ myGLCD.setColor(0, 255, 0);
myGLCD.print("ON", 112, (i*29)+25);
myGLCD.drawRect(102, (i*29)+20, 134, (i*29)+40);
myGLCD.setColor(80, 80, 80); //dark gray
myGLCD.print("OFF", 70, (i*29)+25);
myGLCD.print("AUTO", 30, (i*29)+25);
myGLCD.setColor(190, 190, 190); //light gray
myGLCD.drawRect(66, (i*29)+20, 98, (i*29)+40); //OFF BOX
myGLCD.drawRect(27, (i*29)+20, 63, (i*29)+40); //AUTO BOX
}
if (timerStatus==3) //MANUAL OFF (red)
{ myGLCD.setColor(255, 0, 0);
myGLCD.print("OFF", 70, (i*29)+25);
myGLCD.drawRect(66, (i*29)+20, 98, (i*29)+40);
myGLCD.setColor(80, 80, 80); //dark gray
myGLCD.print("ON", 112, (i*29)+25);
myGLCD.print("AUTO", 30, (i*29)+25);
myGLCD.setColor(190, 190, 190); //light gray
myGLCD.drawRect(102, (i*29)+20, 134, (i*29)+40); //ON BOX
myGLCD.drawRect(27, (i*29)+20, 63, (i*29)+40); //AUTO BOX
}
}
{
int timerStatus;
myGLCD.setFont(SmallFont);
myGLCD.setBackColor(0, 0, 0);
for (int i=0; i<6; i++)
{ if (i==0) { timerStatus=timer7Status;}
if (i==1) { timerStatus=timer8Status;}
if (i==2) { timerStatus=timer9Status;}
if (i==3) { timerStatus=timer10Status;}
if (i==4) { timerStatus=timer11Status;}
if (i==5) { timerStatus=timer12Status;}
if (timerStatus==0) //AUTO OFF (purple)
{ myGLCD.setColor(147, 115, 255);
myGLCD.print("AUTO", 194, (i*29)+25);
myGLCD.drawRect(191, (i*29)+20, 227, (i*29)+40);
myGLCD.setColor(80, 80, 80); //dark gray
myGLCD.print("OFF", 234, (i*29)+25);
myGLCD.print("ON", 272, (i*29)+25);
myGLCD.setColor(190, 190, 190); //light gray
myGLCD.drawRect(230, (i*29)+20, 262, (i*29)+40); //ON BOX
myGLCD.drawRect(265, (i*29)+20, 297, (i*29)+40); //OFF BOX
}
if (timerStatus==1) //AUTO ON (dark green)
{ myGLCD.setColor(0, 100, 0);
myGLCD.print("AUTO", 194, (i*29)+25);
myGLCD.drawRect(191, (i*29)+20, 227, (i*29)+40);
myGLCD.setColor(80, 80, 80); //dark gray
myGLCD.print("OFF", 234, (i*29)+25);
myGLCD.print("ON", 272, (i*29)+25);
myGLCD.setColor(190, 190, 190); //light gray
myGLCD.drawRect(230, (i*29)+20, 262, (i*29)+40); //ON BOX
myGLCD.drawRect(265, (i*29)+20, 297, (i*29)+40); //OFF BOX
}
if (timerStatus==2) //MANUAL ON (green)
{ myGLCD.setColor(0, 255, 0);
myGLCD.print("ON", 272, (i*29)+25);
myGLCD.drawRect(265, (i*29)+20, 297, (i*29)+40);
myGLCD.setColor(80, 80, 80); //dark gray
myGLCD.print("OFF", 234, (i*29)+25);
myGLCD.print("AUTO", 194, (i*29)+25);
myGLCD.setColor(190, 190, 190); //light gray
myGLCD.drawRect(230, (i*29)+20, 262, (i*29)+40); //OFF BOX
myGLCD.drawRect(191, (i*29)+20, 227, (i*29)+40); //AUTO BOX
}
if (timerStatus==3) //MANUAL OFF (red)
{ myGLCD.setColor(255, 0, 0);
myGLCD.print("OFF", 234, (i*29)+25);
myGLCD.drawRect(230, (i*29)+20, 262, (i*29)+40);
myGLCD.setColor(80, 80, 80); //dark gray
myGLCD.print("ON", 272, (i*29)+25);
myGLCD.print("AUTO", 194, (i*29)+25);
myGLCD.setColor(190, 190, 190); //light gray
myGLCD.drawRect(265, (i*29)+20, 297, (i*29)+40); //ON BOX
myGLCD.drawRect(191, (i*29)+20, 227, (i*29)+40); //AUTO BOX
}
}
}
}
void TimerStatusMainScreen()
{
int timerStatus;
myGLCD.setFont(SmallFont);
for (int i=0; i<1; i++)
{ if (i==0) { timerStatus=timer1Status;}
if (timerStatus==0) //Color bar mode AUTO OFF
{ setFont(SMALL, 147, 115, 255, 0, 0, 0);
myGLCD.print("OFF", 78, (i*13)+44);}
if (timerStatus==1) //Color bar mode AUTO ON
{ setFont(SMALL, 0, 100, 0, 0, 0, 0);
myGLCD.print("ON ", 78, (i*13)+44);}
if (timerStatus==2) //Color bar mode MANUALLY ON
{ setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("ON ", 78, (i*13)+44);}
if (timerStatus==3) //Color bar mode MANUALLY OFF
{ setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.print("OFF", 78, (i*13)+44);}
myGLCD.setFont(SmallFont);
for (int i=1; i<2; i++)
{ if (i==1) { timerStatus=timer2Status;}
if (timerStatus==0) //Color bar mode AUTO OFF
{ setFont(SMALL, 147, 115, 255, 0, 0, 0);
myGLCD.print("OFF", 236, (i*13)+31);}
if (timerStatus==1) //Color bar mode AUTO ON
{ setFont(SMALL, 0, 100, 0, 0, 0, 0);
myGLCD.print("ON ", 236, (i*13)+31);}
if (timerStatus==2) //Color bar mode MANUALLY ON
{ setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("ON ", 236, (i*13)+31);}
if (timerStatus==3) //Color bar mode MANUALLY OFF
{ setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.print("OFF", 236, (i*13)+31);} }
myGLCD.setFont(SmallFont);
for (int i=2; i<3; i++)
{ if (i==2) { timerStatus=timer3Status;}
if (timerStatus==0) //Color bar mode AUTO OFF
{ setFont(SMALL, 147, 115, 255, 0, 0, 0);
myGLCD.print("OFF", 76, (i*13)+132);}
if (timerStatus==1) //Color bar mode AUTO ON
{ setFont(SMALL, 0, 100, 0, 0, 0, 0);
myGLCD.print("ON ", 76, (i*13)+132);}
if (timerStatus==2) //Color bar mode MANUALLY ON
{ setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("ON ", 76, (i*13)+132);}
if (timerStatus==3) //Color bar mode MANUALLY OFF
{ setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.print("OFF", 76, (i*13)+132);} }
myGLCD.setFont(SmallFont);
for (int i=3; i<4; i++)
{ if (i==3) { timerStatus=timer4Status;}
if (timerStatus==0) //Color bar mode AUTO OFF
{ setFont(SMALL, 147, 115, 255, 0, 0, 0);
myGLCD.print("OFF", 236, (i*13)+120);}
if (timerStatus==1) //Color bar mode AUTO ON
{ setFont(SMALL, 0, 100, 0, 0, 0, 0);
myGLCD.print("ON ", 236, (i*13)+120);}
if (timerStatus==2) //Color bar mode MANUALLY ON
{ setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("ON ", 236, (i*13)+120);}
if (timerStatus==3) //Color bar mode MANUALLY OFF
{ setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.print("OFF", 236, (i*13)+120);} }
myGLCD.setFont(SmallFont);
for (int i=4; i<5; i++)
{ if (i==4) { timerStatus=timer5Status;}
if (timerStatus==0) //Color bar mode AUTO OFF
{ setFont(SMALL, 147, 115, 255, 0, 0, 0);
myGLCD.print("OFF", 82, (i*13)+12);}
if (timerStatus==1) //Color bar mode AUTO ON
{ setFont(SMALL, 0, 100, 0, 0, 0, 0);
myGLCD.print("ON ", 82, (i*13)+12);}
if (timerStatus==2) //Color bar mode MANUALLY ON
{ setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("ON ", 82, (i*13)+12);}
if (timerStatus==3) //Color bar mode MANUALLY OFF
{ setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.print("OFF", 82, (i*13)+12);} }
myGLCD.setFont(SmallFont);
for (int i=5; i<6; i++)
{ if (i==5) { timerStatus=timer6Status;}
if (timerStatus==0) //Color bar mode AUTO OFF
{ setFont(SMALL, 147, 115, 255, 0, 0, 0);
myGLCD.print("OFF", 243, (i*10)+15);}
if (timerStatus==1) //Color bar mode AUTO ON
{ setFont(SMALL, 0, 100, 0, 0, 0, 0);
myGLCD.print("ON ", 243, (i*10)+15);}
if (timerStatus==2) //Color bar mode MANUALLY ON
{ setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("ON ", 243, (i*10)+15);}
if (timerStatus==3) //Color bar mode MANUALLY OFF
{ setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.print("OFF", 243, (i*10)+15);} }
myGLCD.setFont(SmallFont);
for (int i=6; i<7; i++)
{ if (i==6) { timerStatus=timer7Status;}
if (timerStatus==0) //Color bar mode AUTO OFF
{ setFont(SMALL, 147, 115, 255, 0, 0, 0);
myGLCD.print("OFF", 84, (i*13)+100);}
if (timerStatus==1) //Color bar mode AUTO ON
{ setFont(SMALL, 0, 100, 0, 0, 0, 0);
myGLCD.print("ON ", 84, (i*13)+100);}
if (timerStatus==2) //Color bar mode MANUALLY ON
{ setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("ON ", 84, (i*13)+100);}
if (timerStatus==3) //Color bar mode MANUALLY OFF
{ setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.print("OFF", 84, (i*13)+100);} }
myGLCD.setFont(SmallFont);
for (int i=7; i<8; i++)
{ if (i==7) { timerStatus=timer8Status;}
if (timerStatus==0) //Color bar mode AUTO OFF
{ setFont(SMALL, 147, 115, 255, 0, 0, 0);
myGLCD.print("OFF", 242, (i*13)+88);}
if (timerStatus==1) //Color bar mode AUTO ON
{ setFont(SMALL, 0, 100, 0, 0, 0, 0);
myGLCD.print("ON ", 242, (i*13)+88);}
if (timerStatus==2) //Color bar mode MANUALLY ON
{ setFont(SMALL, 0, 255, 0, 0, 0, 0);
myGLCD.print("ON ", 242, (i*13)+88);}
if (timerStatus==3) //Color bar mode MANUALLY OFF
{ setFont(SMALL, 255, 0, 0, 0, 0, 0);
myGLCD.print("OFF", 242, (i*13)+88);} }
}
}
/*************************** END OF TIMER SCREEN & FUNCTIONS **************************/
{
/************************************ TOUCH SCREEN ************************************/
void processMyTouch()
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
returnTimer=0;
screenSaverCounter=0;
if ((x>=canC[0]) && (x<=canC[2]) && (y>=canC[1]) && (y<=canC[3]) //press cancel
&& (dispScreen!=0) && (dispScreen!=5) && (dispScreen!=6) && (dispScreen!=8)
&& (dispScreen!=9) && (dispScreen!=11) && (dispScreen!=12) && (dispScreen!=14))
{
waitForIt(canC[0], canC[1], canC[2], canC[3]);
ReadFromEEPROM();
dispScreen=0;
clearScreen();
mainScreen(true);
} else
if ((x>=back[0]) && (x<=back[2]) && (y>=back[1]) && (y<=back[3]) //press back
&& (dispScreen!=0) && (dispScreen!=1) && (dispScreen!=5) && (dispScreen!=6)
&& (dispScreen!=7) && (dispScreen!=8) && (dispScreen!=9) && (dispScreen!=11)
&& (dispScreen!=12) && (dispScreen!=13) && (dispScreen!=14) && (dispScreen!=15)
&& (dispScreen!=16) && (dispScreen!=17) && (dispScreen!=18) && (dispScreen!=19)
&& (dispScreen!=21) && (dispScreen!=22) && (dispScreen!=23) && (dispScreen!=24))
{
waitForIt(back[0], back[1], back[2], back[3]);
ReadFromEEPROM();
dispScreen=1;
clearScreen();
menuScreen();
}
else
{
switch (dispScreen) {
case 0: //--------------- MAIN SCREEN (Press Any Key) ----------------------------
if ((x>230) && (x<345) && (y>164) && (y<235))
{
dispScreen=1;
clearScreen();
menuScreen();
}
break;
case 1: //--------------------- MENU SCREEN --------------------------------------
if ((x>=tanD[0]) && (x<=tanD[2])) //first column
{
if ((y>=tanD[1]) && (y<=tanD[3])) //press Date & Clock Screen
{
waitForIt(tanD[0], tanD[1], tanD[2], tanD[3]);
if ((timeDispH>=0) && (timeDispH<=11)) { AM_PM=1;}
else { AM_PM=2;}
dispScreen=2;
clearScreen();
clockScreen();
t_temp = rtc.getTime();
t_temp.dow=calcDOW(rtcSetDy, rtcSetMon, rtcSetYr);
showDOW(t_temp.dow);
}
if ((y>=temC[1]) && (y<=temC[3])) //press H2O Temp Control
{
waitForIt(temC[0], temC[1], temC[2], temC[3]);
ReadFromEEPROM();
dispScreen=3;
clearScreen();
tempScreen(true);
}
if ((y>=wave[1]) && (y<=wave[3])) //press Wavemaker Screen
{
waitForIt(wave[0], wave[1], wave[2], wave[3]);
dispScreen=24;
clearScreen();
graphonoff();
}
if ((y>=gSet[1]) && (y<=gSet[3])) //press General Settings
{
waitForIt(gSet[0], gSet[1], gSet[2], gSet[3]);
dispScreen=14;
clearScreen();
generalSettingsScreen_1();
}
}
if ((x>=TimerS[0]) && (x<=TimerS[2])) //second column
{
if ((y>=TimerS[1]) && (y<=TimerS[3])) //press Timer Settings
{
waitForIt(TimerS[0], TimerS[1], TimerS[2], TimerS[3]);
ReadFromEEPROM();
timerPage=0;
dispScreen=22;
clearScreen();
TimerScreen();
}
if ((y>=about[1]) && (y<=about[3])) //press About sketch
{
waitForIt(about[0], about[1], about[2], about[3]);
dispScreen=20;
clearScreen();
AboutScreen();
}
}
break;
case 2: //--------------- CLOCK & DATE SETUP SCREEN ------------------------------
if ((x>=prSAVE[0]) && (x<=prSAVE[2]) && (y>=prSAVE[1]) && (y<=prSAVE[3])) //press SAVE
{
waitForIt(prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3]);
if (setTimeFormat==1)
{
if ((rtcSetHr==0) && (AM_PM==2))
{ rtcSetHr+=12;}
if (((rtcSetHr>=1) && (rtcSetHr<=11)) && (AM_PM==2))
{ rtcSetHr+=12;}
if (((rtcSetHr>=12) && (rtcSetHr<=23)) && (AM_PM==1))
{ rtcSetHr-=12;}
}
rtc.setTime(rtcSetHr, rtcSetMin, 0);
rtc.setDate(rtcSetDy, rtcSetMon, rtcSetYr);
dispScreen=0;
clearScreen();
mainScreen(true);
}
else
{
if ((y>=houU[1]) && (y<=houU[3])) //FIRST ROW (TIME UP)
{
if ((x>=houU[0]) && (x<=houU[2])) //press hour up
{
waitForIt(houU[0], houU[1], houU[2], houU[3]);
rtcSetHr++;
if (rtcSetHr>=24)
{ rtcSetHr=0; }
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 28);
}
if ((x>=minU[0]) && (x<=minU[2])) //press min up
{
waitForIt(minU[0], minU[1], minU[2], minU[3]);
rtcSetMin++;
if (rtcSetMin>=60) {rtcSetMin = 0; }
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 28);
}
if ((x>=ampmU[0]) && (x<=ampmU[2]) && (setTimeFormat==1)) //press AMPM up
{
waitForIt(ampmU[0], ampmU[1], ampmU[2], ampmU[3]);
if (AM_PM==1) {AM_PM=2;}
else {AM_PM=1;}
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 28);
}
}
if ((y>=houD[1]) && (y<=houD[3])) //SECOND ROW (TIME DOWN)
{
if ((x>=houD[0]) && (x<=houD[2])) //press hour down
{
waitForIt(houD[0], houD[1], houD[2], houD[3]);
rtcSetHr--;
if (rtcSetHr<0)
{ rtcSetHr=23; }
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 28);
}
if ((x>=minD[0]) && (x<=minD[2])) //press min down
{
waitForIt(minD[0], minD[1], minD[2], minD[3]);
rtcSetMin--;
if (rtcSetMin<0) {rtcSetMin = 59; }
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 28);
}
if ((x>=ampmD[0]) && (x<=ampmD[2]) && (setTimeFormat==1)) //press AMPM down
{
waitForIt(ampmD[0], ampmD[1], ampmD[2], ampmD[3]);
if (AM_PM==1) {AM_PM=2;}
else {AM_PM=1;}
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 28);
}
}
if ((y>=dayU[1]) && (y<=dayU[3])) //THIRD ROW (DATE UP)
{
if (setCalendarFormat==0) //DD/MM/YYYY Format
{
if ((x>=dayU[0]) && (x<=dayU[2])) //press day up
{
waitForIt(dayU[0], dayU[1], dayU[2], dayU[3]);
rtcSetDy++;
rtcSetDy=validateDate(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
if ((x>=monU[0]) && (x<=monU[2])) //press month up
{
waitForIt(monU[0], monU[1], monU[2], monU[3]);
rtcSetMon++;
rtcSetDy=validateDateForMonth(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
} else {
if (setCalendarFormat==1) //MM/DD/YYYY Format
{
if ((x>=dayU[0]) && (x<=dayU[2])) //press month up
{
waitForIt(dayU[0], dayU[1], dayU[2], dayU[3]);
rtcSetMon++;
rtcSetDy=validateDateForMonth(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
if ((x>=monU[0]) && (x<=monU[2])) //press day up
{
waitForIt(monU[0], monU[1], monU[2], monU[3]);
rtcSetDy++;
rtcSetDy=validateDate(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
} }
if ((x>=yeaU[0]) && (x<=yeaU[2])) //press year up
{
waitForIt(yeaU[0], yeaU[1], yeaU[2], yeaU[3]);
rtcSetYr++;
rtcSetDy=validateDateForMonth(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
t_temp = rtc.getTime();
t_temp.dow=calcDOW(rtcSetDy, rtcSetMon, rtcSetYr);
showDOW(t_temp.dow);
}
if ((y>=dayD[1]) && (y<=dayD[3])) //FOURTH ROW (DATE DOWN)
{
if (setCalendarFormat==0) //DD/MM/YYYY Format
{
if ((x>=dayD[0]) && (x<=dayD[2])) //press day down
{
waitForIt(dayD[0], dayD[1], dayD[2], dayD[3]);
rtcSetDy--;
rtcSetDy=validateDate(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
if ((x>=monD[0]) && (x<=monD[2])) //press month down
{
waitForIt(monD[0], monD[1], monD[2], monD[3]);
rtcSetMon--;
rtcSetDy=validateDateForMonth(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
} else {
if (setCalendarFormat==1) //MM/DD/YYYY Format
{
if ((x>=dayD[0]) && (x<=dayD[2])) //press month down
{
waitForIt(dayD[0], dayD[1], dayD[2], dayD[3]);
rtcSetMon--;
rtcSetDy=validateDateForMonth(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
if ((x>=monD[0]) && (x<=monD[2])) //press day down
{
waitForIt(monD[0], monD[1], monD[2], monD[3]);
rtcSetDy--;
rtcSetDy=validateDate(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
} }
if ((x>=yeaD[0]) && (x<=yeaD[2])) //press year down
{
waitForIt(yeaD[0], yeaD[1], yeaD[2], yeaD[3]);
rtcSetYr--;
rtcSetDy=validateDateForMonth(rtcSetDy, rtcSetMon, rtcSetYr);
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.print("Changed!", 21, 118);
}
t_temp = rtc.getTime();
t_temp.dow=calcDOW(rtcSetDy, rtcSetMon, rtcSetYr);
showDOW(t_temp.dow);
}
clockScreen(false);
}
break;
case 3: //------------------ H20 TEMPERATURE CONTROL -----------------------------
if ((x>=prSAVE[0]) && (x<=prSAVE[2]) && (y>=prSAVE[1]) && (y<=prSAVE[3])) //press SAVE
{
waitForIt(prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3]);
setTempC = temp2beS;
setTempF = temp2beS;
offTempC = temp2beO;
offTempF = temp2beO;
alarmTempC = temp2beA;
alarmTempF = temp2beA;
if (setTempScale==0) //Celsius to Farenheit (Consistency Conversion)
{
setTempF=((1.8*setTempC)+32.05);
offTempF=((1.8*offTempC)+0.05);
alarmTempF=((1.8*alarmTempC)+0.05);
}
if (setTempScale==1) //Farenheit to Celsius (Consistency Conversion)
{
setTempC=((.55556*(setTempF-32))+.05);
offTempC=(.55556)*offTempF+.05;
alarmTempC=(.55556)*alarmTempF+.05;
}
dispScreen=0;
SaveTempToEEPROM();
clearScreen();
mainScreen(true);
} else
setFont(LARGE, 255, 255, 255, 0, 0, 0);
{
if ((x>=temM[0]) && (x<=temM[2])) //first column
{
if ((y>=temM[1]) && (y<=temM[3])) //press temp minus
{
temp2beS -= 0.1;
if ((setTempScale==1) && (temp2beS <= 50)){
temp2beS = 50; }
if ((setTempScale==0) && (temp2beS <= 10)) {
temp2beS = 10; }
tempScreen();
}
if ((y>=offM[1]) && (y<=offM[3])) //press offset minus
{
temp2beO -= 0.1;
if (temp2beO < 0.1) {
temp2beO = 0.0; }
tempScreen();
}
if ((y>=almM[1]) && (y<=almM[3])) //press alarm minus
{
temp2beA -= 0.1;
if (temp2beA < 0.1) {
temp2beA = 0.0; }
tempScreen();
}
}
if ((x>=temP[0]) && (x<=temP[2])) //second column
{
if ((y>=temP[1]) && (y<=temP[3])) //press temp plus
{
temp2beS += 0.1;
if ((setTempScale==1) && (temp2beS >= 104)){
temp2beS = 104; }
if ((setTempScale==0) && (temp2beS >= 40)) {
temp2beS = 40; }
tempScreen();
}
if ((y>=offP[1]) && (y<=offP[3])) //press offset plus
{
temp2beO += 0.1;
if (temp2beO >= 10) {
temp2beO = 9.9; }
tempScreen();
}
if ((y>=almP[1]) && (y<=almP[3])) //press alarm plus
{
temp2beA += 0.1;
if (temp2beA >= 10) {
temp2beA = 9.9; }
tempScreen();
}
}
}
break;
case 14: //------------- GENERAL SETTINGS (PAGE 1) -----------------------------
if ((x>=backGS[0]) && (x<=backGS[2]) && (y>=backGS[1]) && (y<=backGS[3])) //press back
{
waitForIt(backGS[0], backGS[1], backGS[2], backGS[3]);
ReadFromEEPROM();
dispScreen=1;
clearScreen();
menuScreen();
} else
if ((x>=nextGS[0]) && (x<=nextGS[2]) && (y>=nextGS[1]) && (y<=nextGS[3])) //press next
{
waitForIt(nextGS[0], nextGS[1], nextGS[2], nextGS[3]);
dispScreen=15;
clearScreen();
generalSettingsScreen_2();
} else
if ((x>=prSAVEgs[0]) && (x<=prSAVEgs[2]) && (y>=prSAVEgs[1]) && (y<=prSAVEgs[3])) //press SAVE
{
waitForIt(prSAVEgs[0], prSAVEgs[1], prSAVEgs[2], prSAVEgs[3]);
SaveGenSetsToEEPROM();
dispScreen=1;
clearScreen();
menuScreen();
}
if ((x>=canCgs[0]) && (x<=canCgs[2]) && (y>=canCgs[1]) && (y<=canCgs[3])) //press cancel
{
waitForIt(canCgs[0], canCgs[1], canCgs[2], canCgs[3]);
ReadFromEEPROM();
dispScreen=0;
clearScreen();
mainScreen(true);
} else
if ((x>=185) && (x<=305) && (y>=19) && (y<=39)) //press DD/MM/YYYY Button
{
waitForIt(185, 19, 305, 39);
setFont(SMALL, 255, 255, 0, 64, 64, 64);
myGLCD.print(" ", 1, 227);
setCalendarFormat = 0;
genSetSelect_1();
}
if ((x>=185) && (x<=305) && (y>=45) && (y<=65)) //press Month DD, YYYY Button
{
waitForIt(185, 45, 305, 65);
setFont(SMALL, 255, 255, 0, 64, 64, 64);
myGLCD.print(" ", 1, 227);
setCalendarFormat = 1;
genSetSelect_1();
}
if ((x>=195) && (x<=235)) //first column
{
if ((y>=76) && (y<=96)) //press Show DOW "ON"
{
waitForIt(195, 76, 235, 96);
setFont(SMALL, 255, 255, 0, 64, 64, 64);
myGLCD.print(" ", 16, 227);
displayDOW = 1;
genSetSelect_1();
}
if ((y>=107) && (y<=127)) //press 12HR Button
{
waitForIt(195, 107, 235, 127);
setFont(SMALL, 255, 255, 0, 64, 64, 64);
myGLCD.print(" ", 220, 227);
setTimeFormat = 1;
genSetSelect_1();
}
if ((y>=138) && (y<=158)) //press deg C
{
waitForIt(195, 138, 235, 158);
setTempScale = 0;
genSetSelect_1();
}
}
if ((x>=255) && (x<=295)) //second column
{
if ((y>=76) && (y<=96)) //press Show DOW "OFF"
{
waitForIt(255, 76, 295, 96);
setFont(SMALL, 255, 255, 0, 64, 64, 64);
myGLCD.print(" ", 1, 227);
displayDOW = 0;
genSetSelect_1();
}
if ((y>=107) && (y<=127)) //press 24HR Button
{
waitForIt(255, 107, 295, 127);
setFont(SMALL, 255, 255, 0, 64, 64, 64);
myGLCD.print(" ", 220, 227);
setTimeFormat = 0;
genSetSelect_1();
}
if ((y>=138) && (y<=158)) //press deg F
{
waitForIt(255, 138, 295, 158);
setTempScale = 1;
genSetSelect_1();
}
}
break;
case 15: //------------- GENERAL SETTINGS (PAGE 2) -----------------------------
if ((x>=backGS[0]) && (x<=backGS[2]) && (y>=backGS[1]) && (y<=backGS[3])) //press back
{
waitForIt(backGS[0], backGS[1], backGS[2], backGS[3]);
dispScreen=14;
clearScreen();
generalSettingsScreen_1();
} else
if ((x>=prSAVEgs[0]) && (x<=prSAVEgs[2]) && (y>=prSAVEgs[1]) && (y<=prSAVEgs[3])) //press SAVE
{
waitForIt(prSAVEgs[0], prSAVEgs[1], prSAVEgs[2], prSAVEgs[3]);
SaveGenSetsToEEPROM();
dispScreen=1;
clearScreen();
menuScreen();
}
if ((x>=canCgs[0]) && (x<=canCgs[2]) && (y>=canCgs[1]) && (y<=canCgs[3])) //press cancel
{
waitForIt(canCgs[0], canCgs[1], canCgs[2], canCgs[3]);
ReadFromEEPROM();
dispScreen=0;
clearScreen();
mainScreen(true);
} else
if ((x>=185) && (x<=305) && (y>=129) && (y<=149)) //press SETTINGS (Screensaver)
{
waitForIt(185, 129, 305, 149);
dispScreen=19;
clearScreen();
ScreensaverSettingsScreen();
}
if ((x>=195) && (x<=235)) //first column
{
if ((y>=101) && (y<=121)) //press ON (Screensaver)
{
waitForIt(195, 101, 235, 121);
setScreensaverOnOff = 1;
genSetSelect_2();
}
}
if ((x>=255) && (x<=295)) //second column
{
if ((y>=101) && (y<=121)) //press OFF (Screensaver)
{
waitForIt(255, 101, 295, 121);
setScreensaverOnOff = 0;
genSetSelect_2();
}
}
break;
case 16: //------------- GENERAL SETTINGS (PAGE 3) -----------------------------
case 19: //-------------- SET SCREENSAVER WAIT TIME ----------------------------
if ((x>=back[0]) && (x<=back[2]) && (y>=back[1]) && (y<=back[3])) //press back
{
waitForIt(back[0], back[1], back[2], back[3]);
dispScreen=15;
clearScreen();
generalSettingsScreen_2();
} else
if ((x>=prSAVE[0]) && (x<=prSAVE[2]) && (y>=prSAVE[1]) && (y<=prSAVE[3])) //press SAVE
{
waitForIt(prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3]);
setSSmintues=TempSSminutes;
SaveGenSetsToEEPROM();
dispScreen=15;
clearScreen();
generalSettingsScreen_2();
} else
if ((x>=canC[0]) && (x<=canC[2]) && (y>=canC[1]) && (y<=canC[3])) //press cancel
{
waitForIt(canC[0], canC[1], canC[2], canC[3]);
ReadFromEEPROM();
dispScreen=0;
clearScreen();
mainScreen(true);
} else
if ((x>=185) && (x<=235)) //first column
{
if ((y>=20) && (y<=40)) //press BLANK screensaver
{
waitForIt(185, 20, 235, 40);
setClockOrBlank = 1;
ScreensaverSelect();
}
if ((y>=51) && (y<=71)) //press YES, show Date on Screensaver
{
waitForIt(185, 51, 235, 71);
setScreensaverDOWonOff = 1;
ScreensaverSelect();
}
}
if ((x>=255) && (x<=305)) //second column
{
if ((y>=20) && (y<=40)) //press CLOCK screensaver
{
waitForIt(255, 20, 305, 40);
setClockOrBlank = 0;
ScreensaverSelect();
}
if ((y>=51) && (y<=71)) //press NO, show Date on Screensaver
{
waitForIt(255, 51, 305, 71);
setScreensaverDOWonOff = 0;
ScreensaverSelect();
}
}
if ((x>=175) && (x<=200) && (y>=107) && (y<=132)) //press Minute UP button
{
TempSSminutes++;
setFont(LARGE, 0, 255, 0, 0, 0, 0);
if (TempSSminutes>=99)
{ TempSSminutes=99;}
if (TempSSminutes>=10)
{ myGLCD.printNumI(TempSSminutes, 129, 126);}
else { myGLCD.printNumI(TempSSminutes, 137, 126);}
} else
if ((x>=175) && (x<=200) && (y>=137) && (y<=162)) //press Minute DOWN button
{
TempSSminutes--;
setFont(LARGE, 0, 255, 0, 0, 0, 0);
if (TempSSminutes<=1)
{ TempSSminutes=1;}
if (TempSSminutes>=10)
{ myGLCD.printNumI(TempSSminutes, 129, 126);}
else { myGLCD.printNumI(TempSSminutes, 137, 126);
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(129, 126, 136, 142);
myGLCD.fillRect(153, 126, 161, 142);}
}
break;
case 20: //------------------------- ABOUT -------------------------------------
if ((x>=back[0]) && (x<=back[2]) && (y>=back[1]) && (y<=back[3])) //press back
{
waitForIt(back[0], back[1], back[2], back[3]);
dispScreen=1;
clearScreen();
menuScreen();
}
break;
case 21: //---------------- AUTOMATIC FEEDING CYCLE SCREEN ---------------------
case 22: //------------------- VIEW TIMER SETTINGS -----------------------------
if ((x>=prSAVE[0]) && (x<=prSAVE[2]) && (y>=prSAVE[1]) && (y<=prSAVE[3]) //CONTROL
&& (timerPage==0))
{ waitForIt(prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3]);
dispScreen=24;
clearScreen();
graphonoff();
} else
if ((x>=back[0]) && (x<=back[2]) && (y>back[1]) && (y<=back[3])) //press back
{ waitForIt(back[0], back[1], back[2], back[3]);
ReadFromEEPROM();
if (timerPage==1)
{ dispScreen=24;
clearScreen();
graphonoff();}
else
{ ReadFromEEPROM();
dispScreen=1;
clearScreen();
menuScreen();}
} else
{ if ((x>=5) && (x<=40) && (y>=10) && (y<=110))
{ slctRelay=1; slctONtm=on1; slctOFFtm=off1;}
if ((x>=65) && (x<=100) && (y>=10) && (y<=110))
{ slctRelay=2; slctONtm=on2; slctOFFtm=off2;}
if ((x>=110) && (x<=160) && (y>=10) && (y<=110))
{ slctRelay=3; slctONtm=on3; slctOFFtm=off3;}
if ((x>=165) && (x<=215) && (y>=10) && (y<=110))
{ slctRelay=4; slctONtm=on4; slctOFFtm=off4;}
if ((x>=220) && (x<=240) && (y>=10) && (y<=110))
{ slctRelay=5; slctONtm=on5; slctOFFtm=off5;}
if ((x>=260) && (x<=280) && (y>=10) && (y<=110))
{ slctRelay=6; slctONtm=on6; slctOFFtm=off6;}
if ((x>=5) && (x<=40) && (y>=110) && (y<=200))
{ slctRelay=7; slctONtm=on7; slctOFFtm=off7;}
if ((x>=65) && (x<=90)&& (y>=110) && (y<=200))
{ slctRelay=8; slctONtm=on8; slctOFFtm=off8;}
if ((x>=110) && (x<=160)&& (y>=110) && (y<=200))
{ slctRelay=9; slctONtm=on9; slctOFFtm=off9;}
if ((x>=165) && (x<=215)&& (y>=110) && (y<=200))
{ slctRelay=10; slctONtm=on10; slctOFFtm=off10;}
if ((x>=220) && (x<=240)&& (y>=110) && (y<=200))
{ slctRelay=11; slctONtm=on11; slctOFFtm=off11;}
if ((x>=250) && (x<=280)&& (y>=110) && (y<=200))
{ slctRelay=12; slctONtm=on12; slctOFFtm=off12;}
dispScreen=23;
clearScreen();
RelaySetTimesPage();
}
break;
case 23: //---------------------- SET ON/OFF TIMES -----------------------------
if ((x>=back[0]) && (x<=back[2]) && (y>back[1]) && (y<=back[3])) //press back
{ waitForIt(back[0], back[1], back[2], back[3]);
ReadFromEEPROM();
dispScreen=22;
clearScreen();
TimerScreen();
} else
if ((x>=prSAVE[0]) && (x<=prSAVE[2]) && (y>=prSAVE[1]) && (y<=prSAVE[3])) //press SAVE
{ waitForIt(prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3]);
if (slctRelay==1) { on1=slctONtm; off1=slctOFFtm;}
if (slctRelay==2) { on2=slctONtm; off2=slctOFFtm;}
if (slctRelay==3) { on3=slctONtm; off3=slctOFFtm;}
if (slctRelay==4) { on4=slctONtm; off4=slctOFFtm;}
if (slctRelay==5) { on5=slctONtm; off5=slctOFFtm;}
if (slctRelay==6) { on6=slctONtm; off6=slctOFFtm;}
if (slctRelay==7) { on7=slctONtm; off7=slctOFFtm;}
if (slctRelay==8) { on8=slctONtm; off8=slctOFFtm;}
if (slctRelay==9) { on9=slctONtm; off9=slctOFFtm;}
if (slctRelay==10) { on10=slctONtm; off10=slctOFFtm;}
if (slctRelay==11) { on11=slctONtm; off11=slctOFFtm;}
if (slctRelay==12) { on12=slctONtm; off12=slctOFFtm;}
SaveTimerToEEPROM();
dispScreen=22;
clearScreen();
TimerScreen();
} else
if ((x>=houU[0]) && (x<=houU[2]) && (y>=houU[1]) && (y<=houU[3])) //ON - HOUR+
{ slctONtm=slctONtm+60; RelaySetTimes();}
if ((x>=houD[0]) && (x<=houD[2]) && (y>=houD[1]) && (y<=houD[3])) //ON - HOUR-
{ slctONtm=slctONtm-60; RelaySetTimes();}
if ((x>=minU[0]) && (x<=minU[2]) && (y>=houU[1]) && (y<=houU[3])) //ON - MIN+
{ slctONtm++; RelaySetTimes();}
if ((x>=minD[0]) && (x<=minD[2]) && (y>=houD[1]) && (y<=houD[3])) //ON - MIN-
{ slctONtm--; RelaySetTimes();}
if ((x>=ampmU[0]) && (x<=ampmU[2]) && (y>=houU[1]) && (y<=houU[3]) //ON - AM/PM+
&& (setTimeFormat==1))
{ RelaySetTimes();}
if ((x>=ampmD[0]) && (x<=ampmD[2]) && (y>=houD[1]) && (y<=houD[3]) //ON - AM/PM-
&& (setTimeFormat==1))
{ RelaySetTimes();}
if ((x>=dayU[0]) && (x<=dayU[2]) && (y>=dayU[1]) && (y<=dayU[3])) //OFF - HOUR+
{ slctOFFtm=slctOFFtm+60; RelaySetTimes();}
if ((x>=dayD[0]) && (x<=dayD[2]) && (y>=dayD[1]) && (y<=dayD[3])) //OFF - HOUR-
{ slctOFFtm=slctOFFtm-60; RelaySetTimes();}
if ((x>=monD[0]) && (x<=monD[2]) && (y>=dayU[1]) && (y<=dayU[3])) //OFF - MIN+
{ slctOFFtm++; RelaySetTimes();}
if ((x>=monD[0]) && (x<=monD[2]) && (y>=dayD[1]) && (y<=dayD[3])) //OFF - MIN-
{ slctOFFtm--; RelaySetTimes();}
if ((x>=yeaU[0]) && (x<=yeaU[2]) && (y>=dayU[1]) && (y<=dayU[3]) //ON - AM/PM+
&& (setTimeFormat==1))
{ RelaySetTimes();}
if ((x>=yeaD[0]) && (x<=yeaD[2]) && (y>=dayD[1]) && (y<=dayD[3]) //ON - AM/PM-
&& (setTimeFormat==1))
{ RelaySetTimes();}
break;
case 24: //------------------ MANUAL CONTROL OF TIMERS -------------------------
if ((x>=prSAVE[0]) && (x<=prSAVE[2]) && (y>=prSAVE[1]) && (y<=prSAVE[3]) //TIMERS
&& (timerPage==1))
{ waitForIt(prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3]);
ReadFromEEPROM();
dispScreen=22;
clearScreen();
TimerScreen();
} else
if ((x>=back[0]) && (x<=back[2]) && (y>back[1]) && (y<=back[3])) //press back
{ waitForIt(back[0], back[1], back[2], back[3]);
if (timerPage==1)
{ dispScreen=0;
clearScreen();
mainScreen(true);}
else
{ dispScreen=22;
clearScreen();
TimerScreen();}
} else
if ((x>27) && (x<63) && (y>20) && (y<40)){timer1Status=0;OnOffAuto();} //R1-AUTO
if ((x>102) && (x<134) && (y>20) && (y<40)){timer1Status=2;OnOffAuto();} //R1-ON
if ((x>66) && (x<98) && (y>20) && (y<40)){timer1Status=3;OnOffAuto();} //R1-OFF
if ((x>27) && (x<88) && (y>45) && (y<65)){timer2Status=0;OnOffAuto();} //R2-AUTO
if ((x>102) && (x<124) && (y>45) && (y<65)){timer2Status=2;OnOffAuto();} //R2-ON
if ((x>66) && (x<98) && (y>45) && (y<65)){timer2Status=3;OnOffAuto();} //R2-OFF
if ((x>27) && (x<88) && (y>70) && (y<90)){timer3Status=0;OnOffAuto();} //R3-AUTO
if ((x>102) && (x<124) && (y>70) && (y<90)){timer3Status=2;OnOffAuto();} //R3-ON
if ((x>66) && (x<98) && (y>70) && (y<90)){timer3Status=3;OnOffAuto();} //R3-OFF
if ((x>27) && (x<88) && (y>95) && (y<115)){timer4Status=0;OnOffAuto();}//R4-AUTO
if ((x>102) && (x<124) && (y>95) && (y<115)){timer4Status=2;OnOffAuto();}//R4-ON
if ((x>66) && (x<98) && (y>95) && (y<115)){timer4Status=3;OnOffAuto();}//R4-OFF
if ((x>27) && (x<88) && (y>120) && (y<140)){timer5Status=0;OnOffAuto();}//R5-AUTO
if ((x>102) && (x<124) && (y>120) && (y<140)){timer5Status=2;OnOffAuto();}//R5-ON
if ((x>66) && (x<98) && (y>120) && (y<140)){timer5Status=3;OnOffAuto();}//R5-OFF
if ((x>27) && (x<88) && (y>145) && (y<170)){timer6Status=0;OnOffAuto();}//R5-AUTO
if ((x>102) && (x<124) && (y>145) && (y<170)){timer6Status=2;OnOffAuto();}//R5-ON
if ((x>66) && (x<98) && (y>145) && (y<170)){timer6Status=3;OnOffAuto();}//R5-OFF
if ((x>191) && (x<227) && (y>20) && (y<40)){timer7Status=0;OnOffAuto();} //R1-AUTO
if ((x>264) && (x<292) && (y>20) && (y<40)){timer7Status=2;OnOffAuto();} //R1-ON
if ((x>229) && (x<261) && (y>20) && (y<40)){timer7Status=3;OnOffAuto();} //R1-OFF
if ((x>191) && (x<227) && (y>45) && (y<65)){timer8Status=0;OnOffAuto();} //R2-AUTO
if ((x>264) && (x<292) && (y>45) && (y<65)){timer8Status=2;OnOffAuto();} //R2-ON
if ((x>229) && (x<261) && (y>45) && (y<65)){timer8Status=3;OnOffAuto();} //R2-OFF
if ((x>191) && (x<227) && (y>70) && (y<90)){timer9Status=0;OnOffAuto();} //R3-AUTO
if ((x>264) && (x<292) && (y>70) && (y<90)){timer9Status=2;OnOffAuto();} //R3-ON
if ((x>229) && (x<261) && (y>70) && (y<90)){timer9Status=3;OnOffAuto();} //R3-OFF
if ((x>191) && (x<227) && (y>95) && (y<115)){timer10Status=0;OnOffAuto();}//R4-AUTO
if ((x>264) && (x<292) && (y>95) && (y<115)){timer10Status=2;OnOffAuto();}//R4-ON
if ((x>229) && (x<261) && (y>95) && (y<115)){timer10Status=3;OnOffAuto();}//R4-OFF
if ((x>191) && (x<227) && (y>120) && (y<140)){timer11Status=0;OnOffAuto();}//R5-AUTO
if ((x>264) && (x<292) && (y>120) && (y<140)){timer11Status=2;OnOffAuto();}//R5-ON
if ((x>229) && (x<261) && (y>120) && (y<140)){timer11Status=3;OnOffAuto();}//R5-OFF
if ((x>191) && (x<227) && (y>145) && (y<170)){timer12Status=0;OnOffAuto();}//R5-AUTO
if ((x>264) && (x<292) && (y>145) && (y<170)){timer12Status=2;OnOffAuto();}//R5-ON
if ((x>229) && (x<261) && (y>145) && (y<170)){timer12Status=3;OnOffAuto();}//R5-OFF
break;
}
}
delay(100);
}
/********************************* END of TOUCH SCREEN ********************************/
/**************************************** SETUP **************************************/
void setup()
{
Serial.begin(9600);
TCCR5A = B00101011; // Fast PWM change at OCR5A (Timer 5 - pins 44 & 45)
TCCR5B = B10001; // No Prescalering (Timer 5 - pins 44 & 45)
pinMode(timer1, OUTPUT);
pinMode(timer2, OUTPUT);
pinMode(timer3, OUTPUT);
pinMode(timer4, OUTPUT);
pinMode(timer5, OUTPUT);
pinMode(timer6, OUTPUT);
pinMode(timer7, OUTPUT);
pinMode(timer8, OUTPUT);
pinMode(timer9, OUTPUT);
pinMode(timer10, OUTPUT);
pinMode(timer11, OUTPUT);
pinMode(timer12, OUTPUT);
sensors.begin(); //start up temperature library
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_HI);
myTouch.read();
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 226, 319, 239); //Bottom Bar
rtc.halt(false); //Set the clock to run-mode
min_cnt=(t.hour*60)+t.min;
ReadFromEEPROM();
checkTempC();
screenReturn();
screenSaver();
mainScreen(true);
}
/*********************************** END of SETUP ************************************/
/********************************** BEGIN MAIN LOOP **********************************/
void loop()
{
t = rtc.getTime();
if ((myTouch.dataAvailable()) && (screenSaverCounter>=setScreenSaverTimer))
{
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 226, 319, 239); //Bottom Bar
screenSaverCounter=0;
clearScreen();
mainScreen(true);
dispScreen=0;}
else
{ if (myTouch.dataAvailable())
{ processMyTouch();}}
unsigned long currentMillis = millis();
if (currentMillis - previousMillisFive > 5000) //check time, temp and LED levels every 5s
{ previousMillisFive = currentMillis;
t = rtc.getTime();
RelayStatus();
if (screenSaverCounter<setScreenSaverTimer)
{ TimeDateBar(); }
checkTempC();
OCR5A = 16000000.0 / (2*25000.0); //25kHz PWM - above our audible range so fans are quiet
min_cnt=(t.hour*60)+t.min;
screenReturn();
screenSaver();
if ((dispScreen==0) && (screenSaverCounter<setScreenSaverTimer))
{ mainScreen();}
}
}
/********************************** END OF MAIN LOOP *********************************/}
}
sorry i had to split the program in to 2 parts to post it.
Learning about arrays would save you a lot of code....
Use of functions would make the code more readable...
I would recommend to start a new sketch where you will only run the dimmer. Start simple (one channel gearing up/ down. It will be much easier to help you if you have a simple sketch that needs to do one thing only.
If the simple sketch works, you can merge it into your full sketch.
Is there a library to control this thing?
Or do you have specs how to control it (like PWM pin x to control output 1)
Have you got a wiring scheme?
Have you got a good way to make the connections? 6 jumper wires would maybe work, but the chance of one going lose is substantial and will leave you with a thing that is not working.
You could even start with one LED instead of your module. Then you can see it works and then connect it to the module.... Take small steps and check each step...
Age is not an excuse to do new things.
this is what i have from the maker of the board i would need to change output pins as i use a mega board and also i need to remove time delay and replace them with temperature readings to control pwm pins
{// Testing sketch for 50Hz !!!
#include <TimerOne.h>
unsigned char channel_1 = 7; // Output to Opto Triac pin, channel 1
unsigned char channel_2 = 6; // Output to Opto Triac pin, channel 2
unsigned char channel_3 = 5; // Output to Opto Triac pin, channel 3
unsigned char channel_4 = 4; // Output to Opto Triac pin, channel 4
unsigned char CH1, CH2, CH3, CH4;
unsigned char i=0;
unsigned int delay_time=2500; // delay ms or SPEED
unsigned char clock_tick; // variable for Timer1
void setup() {
pinMode(channel_1, OUTPUT);// Set AC Load pin as output
pinMode(channel_2, OUTPUT);// Set AC Load pin as output
pinMode(channel_3, OUTPUT);// Set AC Load pin as output
pinMode(channel_4, OUTPUT);// Set AC Load pin as output
attachInterrupt(1, zero_crosss_int, RISING);
Timer1.initialize(100); // set a timer of length 100 microseconds for 50Hz or 83 microseconds for 60Hz;
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
}
void timerIsr()
{
clock_tick++;
if (CH1==clock_tick)
{
digitalWrite(channel_1, HIGH); // triac firing
delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_1, LOW); // triac Off
}
if (CH2==clock_tick)
{
digitalWrite(channel_2, HIGH); // triac firing
delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_2, LOW); // triac Off
}
if (CH3==clock_tick)
{
digitalWrite(channel_3, HIGH); // triac firing
delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_3, LOW); // triac Off
}
if (CH4==clock_tick)
{
digitalWrite(channel_4, HIGH); // triac firing
delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_4, LOW); // triac Off
}
}
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
// Every zerocrossing interrupt: For 50Hz (1/2 Cycle) => 10ms ; For 60Hz (1/2 Cycle) => 8.33ms
// 10ms=10000us , 8.33ms=8330us
clock_tick=0;
}
void loop() {
CH1=5; CH2=45; CH3=65; CH4=80;
delay(delay_time);
CH1=80; CH2=65; CH3=45; CH4=5;
delay(delay_time);
CH1=65; CH2=5; CH3=65; CH4=5;
delay(delay_time);
CH1=5; CH2=65; CH3=5; CH4=65;
delay(delay_time);
CH1=5; CH2=65; CH3=65; CH4=5;
delay(delay_time);
CH1=65; CH2=5; CH3=5; CH4=65;
delay(delay_time);
CH1=5; CH2=5; CH3=5; CH4=5;
delay(delay_time);
CH1=95; CH2=95; CH3=95; CH4=95;
delay(delay_time);
}}
drawing is as shown
Using an interrupt to control dimming is.... unusual ![]()
PWM via analogWrite is more conventional.
The boards seems to send a sync signal (zero crossing?).
So seems to be not pwm controllable...
And this makes things difficult as all other parts of the program need to be reasonably fast...
Not really good example code.
4 delays in an interrupt service routine... total 40 micro seconds
Added a few digitalWrites...
And triggered each 100 micro seconds...
...less than 50 micro seconds left to do other things...
...and the other things are far from optimized yet...
I think you need to improve the controller and that that is far beyond your capabilities...
A board that can take pwm would have been much easier.... or does the board allow other controls (where it takes care of the zero crossings on its own?)
This board might be dangerous (insufficient separation of high and low voltage circuits).
Maybe someone else can shine a light on that...
I have done led dimming using mosfet and resistors with timers for aquarium led but as this is mains voltage and i want to control using the temperature inputs. at the moment i use 12 timers switching 3 banks of ssr to power habistat dimmers but i would like more control of the temperature settings than a pot adjustment.
Do you have 3 similar banks working already? Or are those different?
I have touch screen displaying viv number and temperature and 12 timers that switch ssr banks using analog pins i have 8 habistat units powered through the relays and set the temperature on these. i also switch florescent tubes on and off via timers and relays
i was planning to use the power managment pins to run the dimmers as these use to run led sets
So those are on/off switches, not dimmable.
I am afraid a deep dive into hardware timers is needed to control your board while at the same time doing something else...
I hope someone else can follow up on this, as for me this would be new territory too.
I found a schematic of your board. It seems the optocouplers are behind the triacs and invisible on the photos. Separation of high voltage may be OK...
By the way, nice setup you have...
I think this will bring you closer:
//Libraries
#include <RBDdimmer.h>//https://github.com/RobotDynOfficial/RBDDimmer
//Parameters
const int zeroCrossPin = 2;
const int acdPin = 3;
int MIN_POWER = 0;
int MAX_POWER = 80;
int POWER_STEP = 2;
//Variables
int power = 0;
//Objects
dimmerLamp acd(acdPin);
void setup(){
//Init Serial USB
Serial.begin(9600);
Serial.println(F("Initialize System"));
acd.begin(NORMAL_MODE, ON);
}
void loop(){
testDimmer();
}
void testDimmer(){/* function testDimmer */
////Sweep light power to test dimmer
for(power=MIN_POWER;power<=MAX_POWER;power+=POWER_STEP){
acd.setPower(power); // setPower(0-100%);
Serial.print("lampValue -> ");
Serial.print(acd.getPower());
Serial.println("%");
delay(100);
}
for(power=MAX_POWER;power>=MIN_POWER;power-=POWER_STEP){
acd.setPower(power); // setPower(0-100%);
Serial.print("lampValue -> ");
Serial.print(acd.getPower());
Serial.println("%");
delay(100);
}
}
It is written for one channel, but maybe you can simply setup 4 dimmerLamps.
It looks like at least the interface is really straight forward. I did not look at the implementation to see if it allows for any parallel processing (which you will need to run the rest of your program.
I found it here:
https://www.aranacorp.com/en/using-an-ac-light-dimmer-with-arduino/
you are a star thank you, i have code and library and i have a backup unit with a breadboard and can play with it for a bit before moving to main unit.
all my relays have 2 amp fuses attached on the 240v circuit.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.



