Well, I just realized something I should have seen earlier... the thread I found where the OP was modifying the same sketch, the suggestion was to +10 and -10, but doing so means you can't adjust the 01's, only 10's. So, I'm only using +10 for count up, then the regular -1 if I need to count back a few steps. Unless I add separate +10 and -10 buttons(?).
Here's my current edited version in full. Can you suggest a better way? Is it possible to add a longPress duration to determine if going by +1/-1 or +10/-10 depending on the button press?
/*
// Sketch is a modified version of the Typhon firmware v0.3 alpha 2011-16-11,
// Originally developed by N. Enders and R. Ensminger, over at Reef Central forums.
// https://forums.reefcentral.com/threads/who-wants-a-cheap-simple-arduino-based-led-controller.1187729/
*/
// include the libraries:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Button.h>
#include <EEPROM.h>
#include <EEPROMVar.h>
#include <DHT.h>
///// Setup DS18B20 Sensor
#include "OneWire.h"
#include "DallasTemperature.h"
#define ONE_WIRE_BUS 62 //Define the pin of the DS18B20
#define TEMPERATURE_PRECISION 12
int fanPWMpin = 63; //Define the pin of the Fan
const int HtempMin = 50.0; //Define temp when heatsink fan starts (25C = 77F)
const int HtempMax = 95.0; //Define temp when heatsink fan is 100% (35C = 95F)
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/**** Define Variables & Constants ****/
/**************************************/
// Constants
#define DHTPIN 49 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
// set the RTC's I2C address
#define DS1307_I2C_ADDRESS 0x68
// create the LCD
LiquidCrystal lcd(30, 31, 32, 33, 34, 35);
// set up backlight
int bkl = 45; // backlight pin
byte bklIdle = 100; // PWM value for backlight at idle
byte bklOn = 255; // PWM value for backlight when on
int bklDelay = 10000; // ms for the backlight to idle before turning off
unsigned long bklTime = 0; // counter since backlight turned on
// create the menu counter
int menuCount = 1;
int menuSelect = 0;
//create the plus and minus navigation delay counter with its initial maximum of 250.
byte btnMaxDelay = 200;
byte btnMinDelay = 25;
byte btnMaxIteration = 5;
byte btnCurrIteration;
//create manual override variables
boolean override = false;
byte overmenu = 0;
int overpercent = 0;
// create the buttons
Button menu = Button(54, PULLDOWN);
Button select = Button(55, PULLDOWN);
Button plus = Button(56, PULLDOWN);
Button minus = Button(57, PULLDOWN);
Button bklight = Button(58, PULLDOWN);
// LED variables. These control the behavior of lighting. Change these to customize behavoir
int minCounter = 0; // counter that resets at midnight.
int oldMinCounter = 0; // counter that resets at midnight.
int oneLed = 2; // pin for Cool White
int twoLed = 3; // pin for Warm White
int threeLed = 4; // pin for Photo Red
int fourLed = 5; // pin for Far Red
int oneVal = 0; // current value for Cool White
int twoVal = 0; // current value for Warm White
int threeVal = 0; // current value for Photo Red
int fourVal = 0; // current value for Far Red
int onePump = 64; // pin for pump #1
int twoPump = 65; // pin for pump #2
// Variables making use of EEPROM memory:
EEPROMVar<int> oneStartMins = 1319; // minute to start this channel.
EEPROMVar<int> onePhotoPeriod = 720; // photoperiod in minutes for this channel.
EEPROMVar<int> oneMax = 100; // max intensity for this channel, as a percentage
EEPROMVar<int> oneFadeDuration = 30; // duration of the fade on and off for sunrise and sunset for this channel.
EEPROMVar<int> twoStartMins = 1334;
EEPROMVar<int> twoPhotoPeriod = 720;
EEPROMVar<int> twoMax = 100;
EEPROMVar<int> twoFadeDuration = 30;
EEPROMVar<int> threeStartMins = 1349;
EEPROMVar<int> threePhotoPeriod = 720;
EEPROMVar<int> threeMax = 100;
EEPROMVar<int> threeFadeDuration = 30;
EEPROMVar<int> fourStartMins = 1364;
EEPROMVar<int> fourPhotoPeriod = 720;
EEPROMVar<int> fourMax = 100;
EEPROMVar<int> fourFadeDuration = 30;
/// Pump 1 ////////////////////////////
/// Feeding #1
EEPROMVar<int> feedOneStart = 1209;
EEPROMVar<int> feedOneStop = 5;
/// Feeding #2
EEPROMVar<int> feedTwoStart = 1219;
EEPROMVar<int> feedTwoStop = 5;
/// Feeding #3
EEPROMVar<int> feedThreeStart = 1219;
EEPROMVar<int> feedThreeStop = 5;
/// Feeding #4
EEPROMVar<int> feedFourStart = 1219;
EEPROMVar<int> feedFourStop = 5;
/// Pump 2 ////////////////////////////
/// Feeding #1
EEPROMVar<int> feedFiveStart = 1219;
EEPROMVar<int> feedFiveStop = 5;
/// Feeding #2
EEPROMVar<int> feedSixStart = 1219;
EEPROMVar<int> feedSixStop = 5;
/// Feeding #3
EEPROMVar<int> feedSevenStart = 1219;
EEPROMVar<int> feedSevenStop = 5;
/// Feeding #4
EEPROMVar<int> feedEightStart = 1219;
EEPROMVar<int> feedEightStop = 5;
// variables to invert the output PWM signal,
// for use with drivers that consider 0 to be "on"
// i.e. buckpucks. If you need to provide an inverted
// signal on any channel, set the appropriate variable to true.
boolean oneInverted = false;
boolean twoInverted = false;
boolean threeInverted = false;
boolean fourInverted = false;
/****** RTC Functions ******/
/***************************/
// Convert decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val / 10 * 16) + (val % 10) );
}
// Convert binary coded decimal to decimal numbers
byte bcdToDec(byte val)
{
return ( (val / 16 * 10) + (val % 16) );
}
// Sets date and time, starts the clock
void setDate(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
// Gets the date and time
void getDate(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
/****** LED Functions ******/
/***************************/
//function to set LED brightness according to time of day
//function has three equal phases - ramp up, hold, and ramp down
int setLed(int mins, // current time in minutes
int ledPin, // pin for this channel of LEDs
int start, // start time for this channel of LEDs
int period, // photoperiod for this channel of LEDs
int fade, // fade duration for this channel of LEDs
int ledMax, // max value for this channel
boolean inverted // true if the channel is inverted
) {
int val = 0;
//fade up
if (mins > start || mins <= start + fade) {
val = map(mins - start, 0, fade, 0, ledMax);
}
//fade down
if (mins > start + period - fade && mins <= start + period) {
val = map(mins - (start + period - fade), 0, fade, ledMax, 0);
}
//off or post-midnight run.
if (mins <= start || mins > start + period) {
if ((start + period) % 1440 < start && (start + period) % 1440 > mins )
{
val = map((start + period - mins) % 1440, 0, fade, 0, ledMax);
}
else
val = 0;
}
if (val > ledMax) {
val = ledMax;
}
if (val < 0) {
val = 0;
}
if (inverted) {
analogWrite(ledPin, map(val, 0, 100, 255, 0));
}
else {
analogWrite(ledPin, map(val, 0, 100, 0, 255));
}
if (override) {
val = overpercent;
}
return val;
}
/**** Display Functions ****/
/***************************/
//button hold function
int btnCurrDelay(byte curr)
{
if (curr == btnMaxIteration)
{
btnCurrIteration = btnMaxIteration;
return btnMaxDelay;
}
else if (btnCurrIteration == 0)
{
return btnMinDelay;
}
else
{
btnCurrIteration--;
return btnMaxDelay;
}
}
// format a number of minutes into a readable time (24 hr format)
void printMins(int mins, //time in minutes to print
boolean ampm //print am/pm?
) {
int hr = (mins % 1440) / 60;
int mn = mins % 60;
if (hr < 10) {
lcd.print(" ");
}
lcd.print(hr);
lcd.print(":");
if (mn < 10) {
lcd.print("0");
}
lcd.print(mn);
}
// format hours, mins, secs into a readable time (24 hr format)
void printHMS (byte hr,
byte mn,
byte sec //time to print
)
{
if (hr < 10) {
lcd.print(" ");
}
lcd.print(hr, DEC);
lcd.print(":");
if (mn < 10) {
lcd.print("0");
}
lcd.print(mn, DEC);
lcd.print(":");
if (sec < 10) {
lcd.print("0");
}
lcd.print(sec, DEC);
}
void printDate() {
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
// int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int hour = bcdToDec(Wire.read() & 01010010); //24 hour time
int dayOfWeek = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int dayOfMonth = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
////// Uncomment the following to initially set the time and date
////// After you load the sketch, then comment out the section again, and reload the sketch 1 more time.
////// This prevents the sketch from resetting back to the beginning. ;)
second = 0;
minute = 20;
hour = 0;
dayOfWeek = 7;
dayOfMonth = 8;
month = 2;
year = 25;
/// setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
//print the date EG 3/1/11 23:59:59
// lcd.print(dayOfWeek);
switch (dayOfWeek) {
case 1:
lcd.print("Sun");
break;
case 2:
lcd.print("Mon");
break;
case 3:
lcd.print("Tue");
break;
case 4:
lcd.print("Wed");
break;
case 5:
lcd.print("Thu");
break;
case 6:
lcd.print("Fri");
break;
case 7:
lcd.print("Sat");
break;
}
lcd.print(" ");
if (dayOfMonth < 10) {
lcd.print("0");
}
lcd.print(dayOfMonth);
lcd.print(".");
if (month < 10) {
lcd.print("0");
}
lcd.print(month);
// lcd.print(".20");
// if (year < 10){
// lcd.print("0");
// }
// lcd.print(year);
}
void ovrSetAll(int pct) {
analogWrite(oneLed, map(pct, 0, 100, 0, 255));
analogWrite(twoLed, map(pct, 0, 100, 0, 255));
analogWrite(threeLed, map(pct, 0, 100, 0, 255));
analogWrite(fourLed, map(pct, 0, 100, 0, 255));
}
void checkTemp()
{
sensors.requestTemperatures(); // Send the command to get temperatures
delay(10);
float temp1 = 0, temp2 = 0;
// lcd.setCursor(0, 2);
// lcd.print("T:");
temp1 = sensors.getTempFByIndex(0);
// lcd.print(sensors.getTempFByIndex(0));
// lcd.print((char)223);
// lcd.print("F");
// lcd.setCursor(0, 3);
// lcd.print("Led:");
temp2 = sensors.getTempFByIndex(1);
// lcd.print(sensors.getTempFByIndex(1));
// lcd.print((char)223);
// lcd.print("F");
if (temp1 < 0) temp1 = 0; //if sensor not connected reading is -127 deg
else if (temp1 > 99) temp1 = 99;
if (temp2 < 0) temp2 = 0;
else if (temp2 > 99) temp2 = 99;
int tempval1 = int(temp1 * 10);
int tempval2 = int(temp1 * 10);
int fanSpeed1 = map(tempval1, (HtempMin * 10), (HtempMax * 10), 0, 255); //---------heatsink 1 fan control
int fanSpeed2 = map(tempval2, (HtempMin * 10), (HtempMax * 10), 0, 255); //---------heatsink 2 fan control
if (fanSpeed1 <= 0)
fanSpeed1 = 0;
if (fanSpeed1 > 255)
fanSpeed1 = 255;
if (fanSpeed2 <= 0)
fanSpeed2 = 0;
if (fanSpeed2 > 255)
fanSpeed2 = 255;
analogWrite(fanPWMpin, fanSpeed1);
analogWrite(fanPWMpin, fanSpeed2);
Serial.println(fanSpeed1);
Serial.println(fanSpeed2);
// lcd.setCursor(0,1);
// lcd.print(fanSpeed);
}
/**** Setup ****/
/***************/
void setup() {
Wire.begin();
pinMode(bkl, OUTPUT);
lcd.begin(20, 4);
dht.begin();
digitalWrite(bkl, HIGH);
lcd.setCursor(6, 0);
lcd.print("Welcome");
lcd.setCursor(8, 1);
lcd.print("To");
lcd.setCursor(4, 2);
lcd.print("The Garden");
delay(5000);
lcd.clear();
analogWrite(bkl, bklIdle);
btnCurrIteration = btnMaxIteration;
sensors.begin(); // Start up the DS18B20 Temp library
pinMode(fanPWMpin, OUTPUT);
pinMode(onePump, OUTPUT);
digitalWrite(onePump, LOW);
pinMode(twoPump, OUTPUT);
digitalWrite(twoPump, LOW);
}
/***** Loop *****/
/****************/
void loop() {
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
const char* ampm; // Change to a pointer to a string
getDate(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
oldMinCounter = minCounter;
minCounter = hour * 60 + minute;
// Wait a few seconds between measurements.
// delay(10);
float celsius = dht.readTemperature(); // Read temperature in Celsius
float fahrenheit = (celsius * 9 / 5) + 32; // Convert to Fahrenheit
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
lcd.print(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
{
checkTemp();
}
//reset plus & minus acceleration counters if the button's state has changed
if (plus.stateChanged())
{
btnCurrDelay(btnMaxIteration);
}
if (minus.stateChanged())
{
btnCurrDelay(btnMaxIteration);
}
//check & set fade durations
if (oneFadeDuration > onePhotoPeriod / 2 && onePhotoPeriod > 0) {
oneFadeDuration = onePhotoPeriod / 2;
}
if (oneFadeDuration < 1) {
oneFadeDuration = 1;
}
if (twoFadeDuration > twoPhotoPeriod / 2 && twoPhotoPeriod > 0) {
twoFadeDuration = twoPhotoPeriod / 2;
}
if (twoFadeDuration < 1) {
twoFadeDuration = 1;
}
if (threeFadeDuration > threePhotoPeriod / 2 && threePhotoPeriod > 0) {
threeFadeDuration = threePhotoPeriod / 2;
}
if (threeFadeDuration < 1) {
threeFadeDuration = 1;
}
if (fourFadeDuration > fourPhotoPeriod / 2 && fourPhotoPeriod > 0) {
fourFadeDuration = fourPhotoPeriod / 2;
}
if (fourFadeDuration < 1) {
fourFadeDuration = 1;
}
//check & set any time functions
//set outputs
if (!override) {
oneVal = setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, oneFadeDuration, oneMax, oneInverted);
twoVal = setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, twoFadeDuration, twoMax, twoInverted);
threeVal = setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, threeFadeDuration, threeMax, threeInverted);
fourVal = setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fourFadeDuration, fourMax, fourInverted);
}
else {
ovrSetAll(overpercent);
}
/// Backlight Override //////////////////////
if (bklight.uniquePress()) {
analogWrite(bkl, bklOn);
bklTime = millis();
}
//turn the backlight off and reset the menu if the idle time has elapsed
if (bklTime + bklDelay < millis() && bklTime > 0 ) {
analogWrite(bkl, bklIdle);
menuCount = 1;
lcd.clear();
lcd.clear();
bklTime = 0;
}
//iterate through the menus
if (menu.uniquePress()) {
analogWrite(bkl, bklOn);
bklTime = millis();
if (menuCount < 40) {
menuCount++;
} else {
menuCount = 1;
}
lcd.clear();
}
if (menuCount == 1) {
lcd.setCursor(0, 0);
if (hour >= 12) {
ampm = "p";
if (hour > 12) {
hour -= 12;
}
} else {
ampm = "a";
}
printHMS(hour, minute, second);
lcd.setCursor(8, 0);
lcd.print(ampm); // Now prints correctly
lcd.setCursor(11, 0);
printDate();
lcd.setCursor(10, 1);
lcd.print(" ");
lcd.print(sensors.getTempFByIndex(0), 0); //////// Display LED Temp #1
lcd.print((char)223);
lcd.setCursor(15, 1);
lcd.print(" ");
lcd.print(sensors.getTempFByIndex(1), 0); //////// Display LED Temp #2
lcd.print((char)223);
lcd.setCursor(0, 2);
lcd.print("CW:");
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.print(oneVal);
lcd.print("%");
lcd.setCursor(5, 2);
lcd.print("WW:");
lcd.setCursor(5, 3);
lcd.print(" ");
lcd.print(twoVal);
lcd.print("%");
lcd.setCursor(10, 2);
lcd.print("PR:");
lcd.setCursor(10, 3);
lcd.print(" ");
lcd.print(threeVal);
lcd.print("%");
lcd.setCursor(15, 2);
lcd.print("FR:");
lcd.setCursor(15, 3);
lcd.print(" ");
lcd.print(fourVal);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print(fahrenheit, 0);
lcd.print((char)223);
lcd.setCursor(4, 1);
lcd.print(F(" "));
lcd.print(h, 0);
lcd.print(F("%"));
//debugging function to use the select button to advance the timer by 1 minute
//if(select.uniquePress()){setDate(second, minute+1, hour, dayOfWeek, dayOfMonth, month, year);}
}
if (menuCount == 2) {
//Manual Override Menu
lcd.setCursor(0, 0);
lcd.print("Manual Overrides");
lcd.setCursor(0, 3);
lcd.print("All: ");
if (select.uniquePress()) {
if (menuSelect < 3) {
menuSelect++;
}
else {
menuSelect = 0;
}
bklTime = millis();
}
if (menuSelect == 0) {
lcd.print("Timer");
override = false;
}
if (menuSelect == 1) {
lcd.print("ON ");
overpercent = 100;
override = true;
}
if (menuSelect == 2) {
lcd.print("OFF ");
overpercent = 0;
override = true;
}
if (menuSelect == 3) {
override = true;
lcd.print(overpercent, DEC);
lcd.print("% ");
if (plus.isPressed() && overpercent < 100)
{
overpercent++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && overpercent > 0)
{
overpercent--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
}
if (menuCount == 3) {
//set start time for channel one
lcd.setCursor(0, 0);
lcd.print("Cool White Start");
lcd.setCursor(0, 3);
printMins(oneStartMins, true);
if (plus.isPressed() && oneStartMins < 1440) {
oneStartMins = oneStartMins + 10;
if (onePhotoPeriod > 0) {
onePhotoPeriod--;
}
else {
onePhotoPeriod = 1439;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && oneStartMins > 0) {
oneStartMins--;
if (onePhotoPeriod < 1439) {
onePhotoPeriod++;
}
else {
onePhotoPeriod = 0;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 4) {
//set end time for channel one
lcd.setCursor(0, 0);
lcd.print("Cool White End");
lcd.setCursor(0, 3);
printMins(oneStartMins + onePhotoPeriod, true);
if (plus.isPressed()) {
if (onePhotoPeriod < 1439) {
onePhotoPeriod = onePhotoPeriod + 10;
}
else {
onePhotoPeriod = 0;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed()) {
if (onePhotoPeriod > 0) {
onePhotoPeriod--;
}
else {
onePhotoPeriod = 1439;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 5) {
//set fade duration for channel one
lcd.setCursor(0, 0);
lcd.print("Cool White Fade");
lcd.setCursor(0, 3);
printMins(oneFadeDuration, false);
if (plus.isPressed() && (oneFadeDuration < onePhotoPeriod / 2 || oneFadeDuration == 0)) {
oneFadeDuration++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && oneFadeDuration > 1) {
oneFadeDuration--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 6) {
//set intensity for channel one
lcd.setCursor(0, 0);
lcd.print("Cool White Max");
lcd.setCursor(0, 3);
lcd.print(oneMax);
lcd.print(" ");
if (plus.isPressed() && oneMax < 100) {
oneMax++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && oneMax > 0) {
oneMax--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 7) {
//set start time for channel two
lcd.setCursor(0, 0);
lcd.print("Warm White Start");
lcd.setCursor(0, 3);
printMins(twoStartMins, true);
if (plus.isPressed() && twoStartMins < 1440) {
twoStartMins = twoStartMins + 10;
if (twoPhotoPeriod > 0) {
twoPhotoPeriod--;
}
else {
twoPhotoPeriod = 1439;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && twoStartMins > 0) {
twoStartMins--;
if (twoPhotoPeriod < 1439) {
twoPhotoPeriod++;
}
else {
twoPhotoPeriod = 0;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 8) {
//set end time for channel two
lcd.setCursor(0, 0);
lcd.print("Warm White End");
lcd.setCursor(0, 3);
printMins(twoStartMins + twoPhotoPeriod, true);
if (plus.isPressed()) {
if (twoPhotoPeriod < 1439) {
twoPhotoPeriod = twoPhotoPeriod + 10;
}
else {
twoPhotoPeriod = 0;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed()) {
if (twoPhotoPeriod > 0) {
twoPhotoPeriod--;
}
else {
twoPhotoPeriod = 1439;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 9) {
//set fade duration for channel two
lcd.setCursor(0, 0);
lcd.print("Warm White Fade");
lcd.setCursor(0, 3);
printMins(twoFadeDuration, false);
if (plus.isPressed() && (twoFadeDuration < twoPhotoPeriod / 2 || twoFadeDuration == 0)) {
twoFadeDuration++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && twoFadeDuration > 1) {
twoFadeDuration--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 10) {
//set intensity for channel two
lcd.setCursor(0, 0);
lcd.print("Warm White Max");
lcd.setCursor(0, 3);
lcd.print(twoMax);
lcd.print(" ");
if (plus.isPressed() && twoMax < 100) {
twoMax++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && twoMax > 0) {
twoMax--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 11) {
//set start time for channel three
lcd.setCursor(0, 0);
lcd.print("Photo Red Start");
lcd.setCursor(0, 3);
printMins(threeStartMins, true);
if (plus.isPressed() && threeStartMins < 1440) {
threeStartMins = threeStartMins + 10;
if (threePhotoPeriod > 0) {
threePhotoPeriod--;
}
else {
threePhotoPeriod = 1439;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && threeStartMins > 0) {
threeStartMins--;
if (threePhotoPeriod < 1439) {
threePhotoPeriod++;
}
else {
threePhotoPeriod = 0;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 12) {
//set end time for channel three
lcd.setCursor(0, 0);
lcd.print("Photo Red End");
lcd.setCursor(0, 3);
printMins(threeStartMins + threePhotoPeriod, true);
if (plus.isPressed()) {
if (threePhotoPeriod < 1439) {
threePhotoPeriod = threePhotoPeriod + 10;
}
else {
threePhotoPeriod = 0;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed()) {
if (threePhotoPeriod > 0) {
threePhotoPeriod--;
}
else {
threePhotoPeriod = 1439;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 13) {
//set fade duration for channel three
lcd.setCursor(0, 0);
lcd.print("Photo Red Fade");
lcd.setCursor(0, 3);
printMins(threeFadeDuration, false);
if (plus.isPressed() && (threeFadeDuration < threePhotoPeriod / 2 || threeFadeDuration == 0)) {
threeFadeDuration++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && threeFadeDuration > 1) {
threeFadeDuration--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 14) {
//set intensity for channel three
lcd.setCursor(0, 0);
lcd.print("Photo Red Max");
lcd.setCursor(0, 3);
lcd.print(threeMax);
lcd.print(" ");
if (plus.isPressed() && threeMax < 100) {
threeMax++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && threeMax > 0) {
threeMax--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 15) {
//set start time for channel four
lcd.setCursor(0, 0);
lcd.print("Far Red Start");
lcd.setCursor(0, 3);
printMins(fourStartMins, true);
if (plus.isPressed() && fourStartMins < 1440) {
fourStartMins = fourStartMins + 10;
if (fourPhotoPeriod > 0) {
fourPhotoPeriod--;
}
else {
fourPhotoPeriod = 1439;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && fourStartMins > 0) {
fourStartMins--;
if (fourPhotoPeriod < 1439) {
fourPhotoPeriod++;
}
else {
fourPhotoPeriod = 0;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 16) {
//set end time for channel four
lcd.setCursor(0, 0);
lcd.print("Far Red End");
lcd.setCursor(0, 3);
lcd.setCursor(0, 3);
printMins(fourStartMins + fourPhotoPeriod, true);
if (plus.isPressed()) {
if (fourPhotoPeriod < 1439) {
fourPhotoPeriod = fourPhotoPeriod + 10;
}
else {
fourPhotoPeriod = 0;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed()) {
if (fourPhotoPeriod > 0) {
fourPhotoPeriod--;
}
else {
fourPhotoPeriod = 1439;
}
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 17) {
//set fade duration for channel four
lcd.setCursor(0, 0);
lcd.print("Far Red Fade");
lcd.setCursor(0, 3);
printMins(fourFadeDuration, false);
if (plus.isPressed() && (fourFadeDuration < fourPhotoPeriod / 2 || fourFadeDuration == 0)) {
fourFadeDuration++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && fourFadeDuration > 1) {
fourFadeDuration--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 18) {
//set intensity for channel four
lcd.setCursor(0, 0);
lcd.print("Far Red Max");
lcd.setCursor(0, 3);
lcd.print(fourMax);
lcd.print(" ");
if (plus.isPressed() && fourMax < 100) {
fourMax++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && fourMax > 0) {
fourMax--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 19) {
lcd.setCursor(0, 0);
lcd.print("Pump1 Feed 1: Start");
lcd.setCursor(0, 3);
printMins(feedOneStart, true);
lcd.print(" ");
if (plus.isPressed() && feedOneStart < 1440) {
feedOneStart = feedOneStart + 10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedOneStart > 0) {
feedOneStart--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 20) {
lcd.setCursor(0, 0);
lcd.print("Pump1 Feed 1: Stop");
lcd.setCursor(0, 3);
printMins(feedOneStop, true);
lcd.print(" ");
if (plus.isPressed() && feedOneStop < 1439) {
feedOneStop = feedOneStop +10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedOneStop > 0) {
feedOneStop--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 21) {
lcd.setCursor(0, 0);
lcd.print("Pump1 Feed 2: Start");
lcd.setCursor(0, 3);
printMins(feedTwoStart, true);
lcd.print(" ");
if (plus.isPressed() && feedTwoStart < 1440) {
feedTwoStart = feedTwoStart + 10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedTwoStart > 0) {
feedTwoStart--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 22) {
lcd.setCursor(0, 0);
lcd.print("Pump1 Feed 2: Stop");
lcd.setCursor(0, 3);
printMins(feedTwoStop, true);
lcd.print(" ");
if (plus.isPressed() && feedTwoStop < 1439) {
feedTwoStop = feedTwoStop +10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedTwoStop > 0) {
feedTwoStop--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 23) {
lcd.setCursor(0, 0);
lcd.print("Pump1 Feed 3: Start");
lcd.setCursor(0, 3);
printMins(feedThreeStart, true);
lcd.print(" ");
if (plus.isPressed() && feedThreeStart < 1440) {
feedThreeStart = feedThreeStart + 10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedThreeStart > 0) {
feedThreeStart--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 24) {
lcd.setCursor(0, 0);
lcd.print("Pump1 Feed 3: Stop");
lcd.setCursor(0, 3);
printMins(feedThreeStop, true);
lcd.print(" ");
if (plus.isPressed() && feedThreeStop < 1439) {
feedThreeStop = feedThreeStop +10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedThreeStop > 0) {
feedThreeStop--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 25) {
lcd.setCursor(0, 0);
lcd.print("Pump1 Feed 4: Start");
lcd.setCursor(0, 3);
printMins(feedFourStart, true);
lcd.print(" ");
if (plus.isPressed() && feedFourStart < 1440) {
feedFourStart = feedFourStart + 10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedFourStart > 0) {
feedFourStart--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 26) {
lcd.setCursor(0, 0);
lcd.print("Pump1 Feed 4: Stop");
lcd.setCursor(0, 3);
printMins(feedFourStop, true);
lcd.print(" ");
if (plus.isPressed() && feedFourStop < 1439) {
feedFourStop = feedFourStop +10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedFourStop > 0) {
feedFourStop--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 27) {
lcd.setCursor(0, 0);
lcd.print("Pump2 Feed 1: Start");
lcd.setCursor(0, 3);
printMins(feedFiveStart, true);
lcd.print(" ");
if (plus.isPressed() && feedFiveStart < 1440) {
feedFiveStart = feedFiveStart + 10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedFiveStart > 0) {
feedFiveStart--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 28) {
lcd.setCursor(0, 0);
lcd.print("Pump2 Feed 1: Stop");
lcd.setCursor(0, 3);
printMins(feedFiveStop, true);
lcd.print(" ");
if (plus.isPressed() && feedFiveStop < 1439) {
feedFiveStop = feedFiveStop +10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedFiveStop > 0) {
feedFiveStop--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 29) {
lcd.setCursor(0, 0);
lcd.print("Pump2 Feed 2: Start");
lcd.setCursor(0, 3);
printMins(feedSixStart, true);
lcd.print(" ");
if (plus.isPressed() && feedSixStart < 1440) {
feedSixStart = feedSixStart + 10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedSixStart > 0) {
feedSixStart--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 30) {
lcd.setCursor(0, 0);
lcd.print("Pump2 Feed 2: Stop");
lcd.setCursor(0, 3);
printMins(feedSixStop, true);
lcd.print(" ");
if (plus.isPressed() && feedSixStop < 1439) {
feedSixStop = feedSixStop +10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedSixStop > 0) {
feedSixStop--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 31) {
lcd.setCursor(0, 0);
lcd.print("Pump2 Feed 3: Start");
lcd.setCursor(0, 3);
printMins(feedSevenStart, true);
lcd.print(" ");
if (plus.isPressed() && feedSevenStart < 1440) {
feedSevenStart = feedSevenStart + 10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedSevenStart > 0) {
feedSevenStart--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 32) {
lcd.setCursor(0, 0);
lcd.print("Pump2 Feed 3: Stop");
lcd.setCursor(0, 3);
printMins(feedSevenStop, true);
lcd.print(" ");
if (plus.isPressed() && feedSevenStop < 1439) {
feedSevenStop = feedSevenStop +10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedSevenStop > 0) {
feedSevenStop--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 33) {
lcd.setCursor(0, 0);
lcd.print("Pump2 Feed 4: Start");
lcd.setCursor(0, 3);
printMins(feedEightStart, true);
lcd.print(" ");
if (plus.isPressed() && feedEightStart < 1440) {
feedEightStart = feedEightStart + 10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedEightStart > 0) {
feedEightStart--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
if (menuCount == 34) {
lcd.setCursor(0, 0);
lcd.print("Pump2 Feed 4: Stop");
lcd.setCursor(0, 3);
printMins(feedEightStop, true);
lcd.print(" ");
if (plus.isPressed() && feedEightStop < 1439) {
feedEightStop = feedEightStop +10;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && feedEightStop > 0) {
feedEightStop--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (menuCount == 35) {
//set hours
lcd.setCursor(0, 0);
lcd.print("Set Time: Hrs");
lcd.setCursor(0, 3);
printHMS(hour, minute, second);
if (plus.isPressed() && hour < 23) {
hour++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && hour > 0) {
hour--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
if (menuCount == 36) {
//set minutes
lcd.setCursor(0, 0);
lcd.print("Set Time: Mins");
lcd.setCursor(0, 3);
printHMS(hour, minute, second);
if (plus.isPressed() && minute < 59) {
minute++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && minute > 0) {
minute--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
if (menuCount == 37) {
//set dayOfWeek
lcd.setCursor(0, 0);
lcd.print("Set Date: Day");
lcd.setCursor(0, 3);
printDate();
lcd.setCursor(10, 3);
lcd.print(year);
if (plus.isPressed() && dayOfWeek < 7) {
dayOfWeek++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && dayOfWeek > 1) {
dayOfWeek--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
if (menuCount == 38) {
//set dayOfMonth
lcd.setCursor(0, 0);
lcd.print("Set Date: Date");
lcd.setCursor(0, 3);
printDate();
lcd.setCursor(10, 3);
lcd.print(year);
if (plus.isPressed() && dayOfMonth < 31) {
dayOfMonth++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && dayOfMonth > 1) {
dayOfMonth--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
if (menuCount == 39) {
//set Month
lcd.setCursor(0, 0);
lcd.print("Set Date: Month");
lcd.setCursor(0, 3);
printDate();
lcd.setCursor(10, 3);
lcd.print(year);
if (plus.isPressed() && month < 12) {
month++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && month > 1) {
month--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
if (menuCount == 40) {
//set Year
lcd.setCursor(0, 0);
lcd.print("Set Date: Year");
lcd.setCursor(0, 3);
printDate();
lcd.setCursor(10, 3);
lcd.print(year);
if (plus.isPressed() && year < 99) {
year++;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
if (minus.isPressed() && year > 1) {
year--;
delay(btnCurrDelay(btnCurrIteration - 1));
bklTime = millis();
}
setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
}
https://www.nano-reef.com/forums/topic/321174-help-with-led-controller-code-based-on-typhon-almost-done/