Reef Central Online Community

Go Back   Reef Central Online Community > General Interest Forums > Do It Yourself
Blogs FAQ Calendar

Notices

User Tag List

Reply
Thread Tools
Unread 12/10/2011, 11:01 AM   #851
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Seems the library's set up to display a 16x2 display:

From Deuligne.h:
Code:
Deuligne(int devI2CAddress=0xA7, int num_lines=2, int lcdwidth=16, int bufferwidth= 40);
This shows 3 lines in my 16x4 display.. and setting cursor to (0,3) puts it on the second line.. doh!

But adding:
Code:
Deuligne lcd(0xA7, 16, 4);

And now my 4th line is accessible again .


Spuzzum is offline   Reply With Quote
Unread 12/10/2011, 02:39 PM   #852
mm.reefs
Registered Member
 
mm.reefs's Avatar
 
Join Date: Aug 2007
Location: Gurabo, PR USA
Posts: 75
Spuzzum,

Just to say great work!!! I like the different things you are doing to free up more AVR pins in the Typhon, specially the ADC buttons. Like you are doing, some months ago I adapted the MCP23008 LCD interface from the Hydra project and it’s working perfectly with my modified Typhon.

Keep the good ideas flowing!!!


mm.reefs is offline   Reply With Quote
Unread 12/10/2011, 02:39 PM   #853
mm.reefs
Registered Member
 
mm.reefs's Avatar
 
Join Date: Aug 2007
Location: Gurabo, PR USA
Posts: 75
---



Last edited by mm.reefs; 12/10/2011 at 02:46 PM.
mm.reefs is offline   Reply With Quote
Unread 12/10/2011, 05:00 PM   #854
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Thanks mm.reefs

I can do hardware.. to a point, but coding's not my strong point.. otherwise I'd have a crack at modifying for the adc keys. But I can kinda figure things out sometimes.. just takes me a little while.. day, month, etc... I'm better with DOS than c/c++.

But just off the top of my head.. is there a way to disable the backlight option? I'd rather use the PWM channel for LEDs, and just use a dimming pot and an on/off tact switch/button. Push button.. light turns on (or just gets brighter).. do what you need with the menus/display functions, then push button again.. light turns off (or dims back down). That would allow all 6 PWM pins for LEDs. I played by assigning the AREF pin as the backlight pin.. seeing as AREF isn't called in the script I figure it'd be safe.. but not sure really, as it has internal stuffs that I may be screwing up by doing so. I'm not connecting to it.. just using it as a dummy connection in the script.

And another thing I was reading at Arduino's site.. as long as you don't need the serial connection (it's not called in the script).. D0/RX and D1/TX can be used as "regular" digital pins.. relays/sensors/etc...


I also came across something where a guy was using the MCP23008 shift registers for increasing the PWM capabilities.. multiple PWM's off 1 PWM channel. Not too sure how well it works though.. or if I'd want to test on $5 Cree's .


But if I can disable the backlight portion of the script.. then I'm a happy man. I'd be even happier if I could figure out how to add the temp sensor portion. Relays seem easy enough.. it's just all the coding for the sensors that'll be an issue for me.....


Spuzzum is offline   Reply With Quote
Unread 12/10/2011, 05:17 PM   #855
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Also, wanted to mention about the eeprom memory...

People in the satellite community use either a 24LC128 (128Kb) or 24LC256 (256Kb) which holds the eeprom memory, along side an atmel8515 which holds the actual flash/program. It would free up the atmega128/328.. and possibly speed up the entire process. I have no idea as to how to code it though.. and I "think" it's connected to i2c.


Just a thought if you're running out of room in the eeprom.

Maybe I'll talk to a friend who used to be into the community.. see if he knows how to go about it.


Spuzzum is offline   Reply With Quote
Unread 12/11/2011, 10:46 AM   #856
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Putting along....

Success at disabling the backlight in the script.. now have 6 PWM channels working.. and full menu to accommodate the full 6 . Basically just searched for "bkl", then commented out that line. Frees up the PWM pin.. but now, when key hasn't been pressed.. instead of going back to main screen, it just stays at the menu screen you are on. Minor.. but will try to fix.. "somehow". Maybe set the "select" button to send back to "menuCount == 1".. seeing as the select button isn't actually being used.

I also fixed my LCD requiring (-4, 2) or (-4, 3) to start the columns at (0, 2) and (0, 3). It's in the *.cpp files...


Changed:
Code:
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
To:
Code:
int row_offsets[] = { 0x00, 0x40, 0x10, 0x50 };

Now everything works as it should.


Spuzzum is offline   Reply With Quote
Unread 12/11/2011, 12:20 PM   #857
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Fixed the display reset function.. changed "bkl" to "display"...


From:
Code:
// set up backlight
int bkl         = 3;        // backlight digital pin 3
byte bklIdle    = 10;       // PWM value for backlight at idle
byte bklOn      = 70;       // 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
To:
Code:
// set up backlight
byte displayIdle    = 10;       // PWM value for backlight at idle
int displayDelay    = 10000;    // ms for the backlight to idle before turning off
unsigned long displayTime = 0;  // counter since backlight turned on

From:
Code:
  //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();
    bklTime = 0;
  }
To:
Code:
  //turn the backlight off and reset the menu if the idle time has elapsed
  if(displayTime + displayDelay < millis() && displayTime > 0 ){
    menuCount = 1;
    lcd.clear();
    displayTime = 0;
  }

From:
Code:
  //iterate through the menus
  if(menu.uniquePress()){
    analogWrite(bkl,bklOn);
    bklTime = millis();
    if(menuCount < 28){
      menuCount++;
    }else {
      menuCount = 1;
    }
    lcd.clear();
  }
To:
Code:
  //iterate through the menus
  if(menu.uniquePress()){
    displayTime = millis();
    if(menuCount < 28){
      menuCount++;
    }else {
      menuCount = 1;
    }
    lcd.clear();
  }



Spuzzum is offline   Reply With Quote
Unread 12/12/2011, 01:29 PM   #858
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
So here's my modified script.. all 6 PWM channels, and no backlight pin.

Seeing as I managed to get that working, I thought I'd brave it by adding the date as well. Used an example from the Deuligne package, and it worked.

Well.. sort'a

It displays the date I set in the script, and it rolled the date at midnight. All good, right? Not so fast. For some reason, it's not keeping the time now.. never mind the date. When reset.. it literally resets back to the time and date set in the script.


I think I broke it


Attached Files
File Type: txt typhon i2c no bkl 6 channel.txt (29.3 KB, 110 views)
File Type: txt Typhon - 6 channel - Date.txt (30.1 KB, 83 views)
Spuzzum is offline   Reply With Quote
Unread 12/12/2011, 02:45 PM   #859
Baghyyy
Registered Member
 
Join Date: Aug 2008
Posts: 29
Quote:
Originally Posted by Spuzzum View Post
So here's my modified script.. all 6 PWM channels, and no backlight pin.

Seeing as I managed to get that working, I thought I'd brave it by adding the date as well. Used an example from the Deuligne package, and it worked.

Well.. sort'a

It displays the date I set in the script, and it rolled the date at midnight. All good, right? Not so fast. For some reason, it's not keeping the time now.. never mind the date. When reset.. it literally resets back to the time and date set in the script.


I think I broke it

do not lose faith ... go on like this you're doing a good job. congratulations!
I like the electronics I want to work with the community.
I ordered an Arduino board with display, I'm waiting for the shipment arrives.
Then do the tests myself.
now I have only a software simulator for Arduino, it is VirtualBreadboard


Baghyyy is offline   Reply With Quote
Unread 12/12/2011, 02:59 PM   #860
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Thanks Baghyyy... I'm putting along.........


I did just find the issue though.. not sure if this is a half-assed backwards fix, but it's a fix....


Replaced
Code:
  second = 0;
  minute = 6;
  hour = 22;
  dayOfWeek = 2;
  dayOfMonth = 12;
  month = 12;
  year = 11;

  setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

With
Code:
//////   Uncomment the following to initially set the time and date
//////   After you load the sketch, the comment out the section again, and reload the sketch 1 more time.
//////   This prevents the sketch from restting back to the beginning. ;)


/*  
  second = 0;
  minute = 6;
  hour = 22;
  dayOfWeek = 2;
  dayOfMonth = 12;
  month = 12;
  year = 11;

  setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
*/

Unplugged for a few minutes.. time keeps up .


Now to look into setting up a menu option for manually adjusting the date. Will take some thinking...


After that.. would still like to look into the adc key option. Doesn't look too much different.. but we'll see.


Spuzzum is offline   Reply With Quote
Unread 12/12/2011, 04:06 PM   #861
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Scratch that...

Looking at an example for DS1307, it's just the setDateDs1307 that needs commenting out...

Code:
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 0;
minute = 37;
hour = 0;
dayOfWeek = 5;
dayOfMonth = 20;
month = 5;
year = 10;
// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}



Spuzzum is offline   Reply With Quote
Unread 12/12/2011, 04:14 PM   #862
TheFishMan65
Registered Member
 
Join Date: Aug 2009
Location: Northern VA
Posts: 4,618
True, but commenting the whole thing out will save program memory that may become a precious commodity


__________________
Click my home page for Thread Summaries

Current Tank Info: 75 gallon lps and fish
TheFishMan65 is offline   Reply With Quote
Unread 12/12/2011, 06:48 PM   #863
zero2007
Registered Member
 
Join Date: Jun 2011
Posts: 8
Hi Spuzzum,

Can you post your script for your 6 channel version? as the txt file you uploaded is hard to work with.

Keep up the good work..

Zero


zero2007 is offline   Reply With Quote
Unread 12/13/2011, 11:54 AM   #864
shark boy
Registered Member
 
shark boy's Avatar
 
Join Date: Jul 2011
Posts: 118
Spuzzum,

I've been trying to follow you on the conversion but I'm having problems.
Could you post a summery. Like a list of new materials" the 4x16 lcd, new button changes, or joystick", pinout changes, and so forth.

On the I2C, is the channel maxxed with the lcd and control buttons or could we still add a temp probe and such?

I have a working original Typhon and would love to upgrade it to the level your describing.

Thanks,
shark boy


shark boy is offline   Reply With Quote
Unread 12/13/2011, 07:01 PM   #865
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Sorry... had to split it up.. can't post all as 1

pt. 1:
Code:
/*
 *
 * This is a modified version of the Typhon script.
 *
 * For use with Deuligne i2clcd backpacks - uses the MCP23008 chip
 *
 * Deuligne Schematic:
 * http://shop.snootlab.com/attachment.php?id_attachment=56
 * 
 * Deuligne Library can be foind at github:
 * https://github.com/Snootlab/Deuligne
 *
 * All other files needed at Deuligne's site under the "download" tab:
 * http://shop.snootlab.com/lang-en/powerduino/135-deuligne.html#idTab9
 *
 *
 *
 *
// Typhon firmware
// v0.3 alpha 2011-16-11
// N. Enders, R. Ensminger
//
// This sketch provides firmware for the Typhon LED controller.
// It provides a structure to fade 4 independent channels of LED lighting
// on and off each day, to simulate sunrise and sunset.
//
// Current work in progress:
// - store all LED variables in EEPROM so they are not reset by a loss of power
// - allow for signals to be inverted for buckpucks or other drivers that consider 0 to be "on"
//
// Future developments may include:
// - moon phase simulation
// - storm simulation
// - support for plugin hardware modules for temperature, pH, relay control, etc.
// 
// Sketch developed in Arduino-22
// Requires LiquidCrystal, Wire, EEPROM, EEPROMVar, and Button libraries.
// Button is available here: http://www.arduino.cc/playground/Code/Button
// EEPROMVar is available here: http://www.arduino.cc/playground/uploads/Profiles/EEPROMVar_01.zip
 */

// include the libraries:
#include 
#include 
#include 
#include 
#include 

// set the RTC's I2C address
#define DS1307_I2C_ADDRESS 0x68

// create the LCD
Deuligne lcd(0xA7, 16, 4);

int lcdDelay    = 10000;    // ms for the backlight to idle before turning off
unsigned long lcdTime = 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(14,BUTTON_PULLDOWN);
Button select   = Button(15,BUTTON_PULLDOWN);
Button plus     = Button(16,BUTTON_PULLDOWN);
Button minus    = Button(17,BUTTON_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 = 3;             // pin for channel 1
int twoLed = 5;             // pin for channel 2
int threeLed = 6;           // pin for channel 3
int fourLed = 9;            // pin for channel 4
int fiveLed = 10;           // pin for channel 5
int sixLed = 11;            // pin for channel 6


int oneVal = 0;             // current value for channel 1
int twoVal = 0;             // current value for channel 2
int threeVal = 0;           // current value for channel 3
int fourVal = 0;            // current value for channel 4
int fiveVal = 0;            // current value for channel 5
int sixVal = 0;             // current value for channel 6

// Variables making use of EEPROM memory:

EEPROMVar oneStartMins = 750;      // minute to start this channel.
EEPROMVar onePhotoPeriod = 720;   // photoperiod in minutes for this channel.
EEPROMVar oneMax = 100;           // max intensity for this channel, as a percentage
EEPROMVar oneFadeDuration = 60;   // duration of the fade on and off for sunrise and sunset for
//    this channel.
EEPROMVar twoStartMins = 810;
EEPROMVar twoPhotoPeriod = 600;
EEPROMVar twoMax = 100;
EEPROMVar twoFadeDuration = 60;

EEPROMVar threeStartMins = 810;
EEPROMVar threePhotoPeriod = 600;
EEPROMVar threeMax = 100;
EEPROMVar threeFadeDuration = 60;

EEPROMVar fourStartMins = 480;
EEPROMVar fourPhotoPeriod = 510;  
EEPROMVar fourMax = 100;          
EEPROMVar fourFadeDuration = 60;  

EEPROMVar fiveStartMins = 480;
EEPROMVar fivePhotoPeriod = 510;  
EEPROMVar fiveMax = 100;          
EEPROMVar fiveFadeDuration = 60;  

EEPROMVar sixStartMins = 480;
EEPROMVar sixPhotoPeriod = 510;  
EEPROMVar sixMax = 100;          
EEPROMVar sixFadeDuration = 60;  

// 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;
boolean fiveInverted = false;
boolean sixInverted = false;



Spuzzum is offline   Reply With Quote
Unread 12/13/2011, 07:03 PM   #866
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
pt. 2:

Code:
/*
   int oneStartMins = 1380;      // minute to start this channel.
   int onePhotoPeriod = 120;   // photoperiod in minutes for this channel.
   int oneMax = 100;           // max intensity for this channel, as a percentage
   int oneFadeDuration = 60;   // duration of the fade on and off for sunrise and sunset for
//    this channel.                                    
int twoStartMins = 800;
int twoPhotoPeriod = 60;
int twoMax = 100;
int twoFadeDuration = 15;

int threeStartMins = 800;
int threePhotoPeriod = 60;
int threeMax = 100;
int threeFadeDuration = 30;

int fourStartMins = 800;
int fourPhotoPeriod = 120;  
int fourMax = 100;          
int fourFadeDuration = 60;  

int fiveStartMins = 800;
int fivePhotoPeriod = 120;  
int fiveMax = 100;          
int fiveFadeDuration = 60;

int sixStartMins = 800;
int sixPhotoPeriod = 120;  
int sixMax = 100;          
int sixFadeDuration = 60;
 */

/****** 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 setDateDs1307(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.send(0);
	Wire.send(decToBcd(second));
	Wire.send(decToBcd(minute));
	Wire.send(decToBcd(hour));
	Wire.send(decToBcd(dayOfWeek));
	Wire.send(decToBcd(dayOfMonth));
	Wire.send(decToBcd(month));
	Wire.send(decToBcd(year));
	Wire.endTransmission();
}

// Gets the date and time
void getDateDs1307(byte *second,
		byte *minute,
		byte *hour,
		byte *dayOfWeek,
		byte *dayOfMonth,
		byte *month,
		byte *year)
{
	Wire.beginTransmission(DS1307_I2C_ADDRESS);
	Wire.send(0);
	Wire.endTransmission();
	Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
	*second     = bcdToDec(Wire.receive() & 0x7f);
	*minute     = bcdToDec(Wire.receive());
	*hour       = bcdToDec(Wire.receive() & 0x3f);
	*dayOfWeek  = bcdToDec(Wire.receive());
	*dayOfMonth = bcdToDec(Wire.receive());
	*month      = bcdToDec(Wire.receive());
	*year       = bcdToDec(Wire.receive());
}

/****** 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.send(0);
	Wire.endTransmission();

	Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

	int second = bcdToDec(Wire.receive());
	int minute = bcdToDec(Wire.receive());
	int hour = bcdToDec(Wire.receive() & 0b111111); //24 hour time
	int dayOfWeek = bcdToDec(Wire.receive()); //0-6 -> sunday - Saturday
	int dayOfMonth = bcdToDec(Wire.receive());
	int month = bcdToDec(Wire.receive());
	int year = bcdToDec(Wire.receive());

	//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));
	analogWrite(fiveLed,map(pct,0,100,0,255));
	analogWrite(sixLed,map(pct,0,100,0,255));
}



Spuzzum is offline   Reply With Quote
Unread 12/13/2011, 07:04 PM   #867
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
pt. 3:

Code:
/**** Setup ****/
/***************/

void setup() {
	byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
	Wire.begin();
	Serial.begin(9600);


	//////   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 = 6;
	hour = 22;
	dayOfWeek = 2;
	dayOfMonth = 12;
	month = 12;
	year = 11;

	///  setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);




	Wire.begin();
	lcd.init();
	lcd.print("Typhon-Reef");
	lcd.setCursor(0,1);
	lcd.print("");
	delay(5000);
	lcd.clear();
	btnCurrIteration = btnMaxIteration;
}

/***** Loop *****/
/****************/

void loop() {
	byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

	getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
	oldMinCounter = minCounter;
	minCounter = hour * 60 + minute;

	//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;}

	if(fiveFadeDuration > fivePhotoPeriod/2 && fivePhotoPeriod > 0){fiveFadeDuration = fivePhotoPeriod/2;}
	if(fiveFadeDuration<1){fiveFadeDuration=1;}

	if(sixFadeDuration > sixPhotoPeriod/2 && sixPhotoPeriod > 0){sixFadeDuration = sixPhotoPeriod/2;}
	if(sixFadeDuration<1){sixFadeDuration=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);
		fiveVal = setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fiveFadeDuration, fiveMax, fiveInverted);
		sixVal = setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, sixFadeDuration, sixMax, sixInverted);
	}
	else{
		ovrSetAll(overpercent);
	}


	//turn the backlight off and reset the menu if the idle time has elapsed
	if(lcdTime + lcdDelay < millis() && lcdTime > 0 ){
		menuCount = 1;
		lcd.clear();
		lcdTime = 0;
	}

	//iterate through the menus
	if(menu.uniquePress()){
		lcdTime = millis();
		if(menuCount < 32){   /////////////////////////////////////////////////////////////////////  menu count
			menuCount++;
		}else {
			menuCount = 1;
		}
		lcd.clear();
	}
	if(menuCount == 1){
		//main screen turn on!!!
		if (minCounter > oldMinCounter){
			lcd.clear();
		}
		lcd.setCursor(0,0);
		printHMS(hour, minute, second);
		lcd.setCursor(0,1);
		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(" ");
		lcd.print(dayOfMonth, DEC);
		lcd.print("/");
		lcd.print(month, DEC);
		lcd.print("/20");
		lcd.print(year, DEC);
		lcd.setCursor(0,2);
		lcd.print("1-3:");
		lcd.setCursor(5,2);
		lcd.print(oneVal);
		lcd.setCursor(9,2);
		lcd.print(twoVal);
		lcd.setCursor(13,2);
		lcd.print(threeVal);
		lcd.setCursor(0,3);
		lcd.print("4-6:");
		lcd.setCursor(5,3);
		lcd.print(fourVal);
		lcd.setCursor(9,3);
		lcd.print(fiveVal);
		lcd.setCursor(13,3);
		lcd.print(sixVal);
		//debugging function to use the select button to advance the timer by 1 minute
		//if(select.uniquePress()){setDateDs1307(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,1);
		lcd.print("All: ");
		if(select.uniquePress()){
			if(menuSelect < 3){menuSelect++;}
			else{menuSelect = 0;}
			lcdTime = 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));
							lcdTime = millis();
						}

						if(minus.isPressed() && overpercent > 0)
						{
							overpercent--;
							delay(btnCurrDelay(btnCurrIteration-1));
							lcdTime = millis();
						}
					}
	}



	if(menuCount == 3){
		//set start time for channel one
		lcd.setCursor(0,0);
		lcd.print("Channel 1 Start");
		lcd.setCursor(0,1);
		printMins(oneStartMins, true);

		if(plus.isPressed() && oneStartMins < 1440){
			oneStartMins++;
			if(onePhotoPeriod >0){onePhotoPeriod--;}
			else{onePhotoPeriod=1439;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && oneStartMins > 0){
			oneStartMins--;
			if(onePhotoPeriod<1439){onePhotoPeriod++;}
			else{onePhotoPeriod=0;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 4){
		//set end time for channel one
		lcd.setCursor(0,0);
		lcd.print("Channel 1 End");
		lcd.setCursor(0,1);
		printMins(oneStartMins+onePhotoPeriod, true);
		if(plus.isPressed()){
			if(onePhotoPeriod < 1439){
				onePhotoPeriod++;}
			else{
				onePhotoPeriod=0;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed()){
			if(onePhotoPeriod >0){
				onePhotoPeriod--;}
			else{
				onePhotoPeriod=1439;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 5){
		//set fade duration for channel one
		lcd.setCursor(0,0);
		lcd.print("Channel 1 Fade");
		lcd.setCursor(0,1);
		printMins(oneFadeDuration, false);
		if(plus.isPressed() && (oneFadeDuration < onePhotoPeriod/2 || oneFadeDuration == 0)){
			oneFadeDuration++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && oneFadeDuration > 1){
			oneFadeDuration--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 6){
		//set intensity for channel one
		lcd.setCursor(0,0);
		lcd.print("Channel 1 Max");
		lcd.setCursor(1,1);
		lcd.print(oneMax);
		lcd.print("  ");
		if(plus.isPressed() && oneMax < 100){
			oneMax++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && oneMax > 0){
			oneMax--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 7){
		//set start time for channel two
		lcd.setCursor(0,0);
		lcd.print("Channel 2 Start");
		lcd.setCursor(0,1);
		printMins(twoStartMins, true);
		if(plus.isPressed() && twoStartMins < 1440){
			twoStartMins++;
			if(twoPhotoPeriod >0){twoPhotoPeriod--;}
			else{twoPhotoPeriod=1439;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && twoStartMins > 0){
			twoStartMins--;
			if(twoPhotoPeriod<1439){twoPhotoPeriod++;}
			else{twoPhotoPeriod=0;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 8){
		//set end time for channel two
		lcd.setCursor(0,0);
		lcd.print("Channel 2 End");
		lcd.setCursor(0,1);
		printMins(twoStartMins+twoPhotoPeriod, true);
		if(plus.isPressed()){
			if(twoPhotoPeriod < 1439){
				twoPhotoPeriod++;}
			else{
				twoPhotoPeriod=0;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed()){
			if(twoPhotoPeriod >0){
				twoPhotoPeriod--;}
			else{
				twoPhotoPeriod=1439;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 9){
		//set fade duration for channel two
		lcd.setCursor(0,0);
		lcd.print("Channel 2 Fade");
		lcd.setCursor(0,1);
		printMins(twoFadeDuration, false);
		if(plus.isPressed() && (twoFadeDuration < twoPhotoPeriod/2 || twoFadeDuration == 0)){
			twoFadeDuration++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && twoFadeDuration > 1){
			twoFadeDuration--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 10){
		//set intensity for channel two
		lcd.setCursor(0,0);
		lcd.print("Channel 2 Max");
		lcd.setCursor(1,1);
		lcd.print(twoMax);
		lcd.print("  ");
		if(plus.isPressed() && twoMax < 100){
			twoMax++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && twoMax > 0){
			twoMax--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 11){
		//set start time for channel three
		lcd.setCursor(0,0);
		lcd.print("Channel 3 Start");
		lcd.setCursor(0,1);
		printMins(threeStartMins, true);
		if(plus.isPressed() && threeStartMins < 1440){
			threeStartMins++;
			if(threePhotoPeriod >0){threePhotoPeriod--;}
			else{threePhotoPeriod=1439;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && threeStartMins > 0){
			threeStartMins--;
			if(threePhotoPeriod<1439){threePhotoPeriod++;}
			else{threePhotoPeriod=0;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 12){
		//set end time for channel three
		lcd.setCursor(0,0);
		lcd.print("Channel 3 End");
		lcd.setCursor(0,1);
		printMins(threeStartMins+threePhotoPeriod, true);
		if(plus.isPressed()){
			if(threePhotoPeriod < 1439){
				threePhotoPeriod++;}
			else{
				threePhotoPeriod=0;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed()){
			if(threePhotoPeriod >0){
				threePhotoPeriod--;}
			else{
				threePhotoPeriod=1439;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 13){
		//set fade duration for channel three
		lcd.setCursor(0,0);
		lcd.print("Channel 3 Fade");
		lcd.setCursor(0,1);
		printMins(threeFadeDuration, false);
		if(plus.isPressed() && (threeFadeDuration < threePhotoPeriod/2 || threeFadeDuration == 0)){
			threeFadeDuration++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && threeFadeDuration > 1){
			threeFadeDuration--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 14){
		//set intensity for channel three
		lcd.setCursor(0,0);
		lcd.print("Channel 3 Max");
		lcd.setCursor(1,1);
		lcd.print(threeMax);
		lcd.print("  ");
		if(plus.isPressed() && threeMax < 100){
			threeMax++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && threeMax > 0){
			threeMax--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 15){
		//set start time for channel four
		lcd.setCursor(0,0);
		lcd.print("Channel 4 Start");
		lcd.setCursor(0,1);
		printMins(fourStartMins, true);
		if(plus.isPressed() && fourStartMins < 1440){
			fourStartMins++;
			if(fourPhotoPeriod >0){fourPhotoPeriod--;}
			else{fourPhotoPeriod=1439;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && fourStartMins > 0){
			fourStartMins--;
			if(fourPhotoPeriod<1439){fourPhotoPeriod++;}
			else{fourPhotoPeriod=0;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 16){
		//set end time for channel four
		lcd.setCursor(0,0);
		lcd.print("Channel 4 End");
		lcd.setCursor(0,1);
		printMins(fourStartMins+fourPhotoPeriod, true);
		if(plus.isPressed()){
			if(fourPhotoPeriod < 1439){
				fourPhotoPeriod++;}
			else{
				fourPhotoPeriod=0;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed()){
			if(fourPhotoPeriod >0){
				fourPhotoPeriod--;}
			else{
				fourPhotoPeriod=1439;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 17){
		//set fade duration for channel four
		lcd.setCursor(0,0);
		lcd.print("Channel 4 Fade");
		lcd.setCursor(0,1);
		printMins(fourFadeDuration, false);
		if(plus.isPressed() && (fourFadeDuration < fourPhotoPeriod/2 || fourFadeDuration == 0)){
			fourFadeDuration++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && fourFadeDuration > 1){
			fourFadeDuration--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 18){
		//set intensity for channel four
		lcd.setCursor(0,0);
		lcd.print("Channel 4 Max");
		lcd.setCursor(1,1);
		lcd.print(fourMax);
		lcd.print("   ");
		if(plus.isPressed() && fourMax < 100){
			fourMax++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && fourMax > 0){
			fourMax--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 19){
		//set start time for channel five
		lcd.setCursor(0,0);
		lcd.print("Channel 5 Start");
		lcd.setCursor(0,1);
		printMins(fiveStartMins, true);
		if(plus.isPressed() && fiveStartMins < 1440){
			fiveStartMins++;
			if(fivePhotoPeriod >0){fivePhotoPeriod--;}
			else{fivePhotoPeriod=1439;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && fiveStartMins > 0){
			fiveStartMins--;
			if(fivePhotoPeriod<1439){fivePhotoPeriod++;}
			else{fivePhotoPeriod=0;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 20){
		//set end time for channel five
		lcd.setCursor(0,0);
		lcd.print("Channel 5 End");
		lcd.setCursor(0,1);
		printMins(fiveStartMins+fivePhotoPeriod, true);
		if(plus.isPressed()){
			if(fivePhotoPeriod < 1439){
				fivePhotoPeriod++;}
			else{
				fivePhotoPeriod=0;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed()){
			if(fivePhotoPeriod >0){
				fivePhotoPeriod--;}
			else{
				fivePhotoPeriod=1439;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 21){
		//set fade duration for channel five
		lcd.setCursor(0,0);
		lcd.print("Channel 5 Fade");
		lcd.setCursor(0,1);
		printMins(fiveFadeDuration, false);
		if(plus.isPressed() && (fiveFadeDuration < fivePhotoPeriod/2 || fiveFadeDuration == 0)){
			fiveFadeDuration++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && fiveFadeDuration > 1){
			fiveFadeDuration--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 22){
		//set intensity for channel five
		lcd.setCursor(0,0);
		lcd.print("Channel 5 Max");
		lcd.setCursor(1,1);
		lcd.print(fiveMax);
		lcd.print("   ");
		if(plus.isPressed() && fiveMax < 100){
			fiveMax++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && fiveMax > 0){
			fiveMax--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 23){
		//set start time for channel six
		lcd.setCursor(0,0);
		lcd.print("Channel 6 Start");
		lcd.setCursor(0,1);
		printMins(sixStartMins, true);
		if(plus.isPressed() && sixStartMins < 1440){
			sixStartMins++;
			if(sixPhotoPeriod >0){sixPhotoPeriod--;}
			else{sixPhotoPeriod=1439;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && sixStartMins > 0){
			sixStartMins--;
			if(sixPhotoPeriod<1439){sixPhotoPeriod++;}
			else{sixPhotoPeriod=0;}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 24){
		//set end time for channel six
		lcd.setCursor(0,0);
		lcd.print("Channel 6 End");
		lcd.setCursor(0,1);
		printMins(sixStartMins+sixPhotoPeriod, true);
		if(plus.isPressed()){
			if(sixPhotoPeriod < 1439){
				sixPhotoPeriod++;}
			else{
				sixPhotoPeriod=0;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed()){
			if(sixPhotoPeriod >0){
				sixPhotoPeriod--;}
			else{
				sixPhotoPeriod=1439;
			}
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 25){
		//set fade duration for channel six
		lcd.setCursor(0,0);
		lcd.print("Channel 6 Fade");
		lcd.setCursor(0,1);
		printMins(sixFadeDuration, false);
		if(plus.isPressed() && (sixFadeDuration < sixPhotoPeriod/2 || sixFadeDuration == 0)){
			sixFadeDuration++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && sixFadeDuration > 1){
			sixFadeDuration--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 26){
		//set intensity for channel six
		lcd.setCursor(0,0);
		lcd.print("Channel 6 Max");
		lcd.setCursor(1,1);
		lcd.print(sixMax);
		lcd.print("   ");
		if(plus.isPressed() && sixMax < 100){
			sixMax++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && sixMax > 0){
			sixMax--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
	}

	if(menuCount == 27){
		//set hours
		lcd.setCursor(0,0);
		lcd.print("Set Time: Hrs");
		lcd.setCursor(0,1);
		printHMS(hour, minute, second);
		if(plus.isPressed() && hour < 23){
			hour++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && hour > 0){
			hour--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
	}

	if(menuCount == 28){
		//set minutes
		lcd.setCursor(0,0);
		lcd.print("Set Time: Mins");
		lcd.setCursor(0,1);
		printHMS(hour, minute, second);
		if(plus.isPressed() && minute < 59){
			minute++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && minute > 0){
			minute--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
	}

	if(menuCount == 29){
		//set dayOfWeek
		lcd.setCursor(0,0);
		lcd.print("Set Date: Day");
		lcd.setCursor(0,2);
		printDate();
		if(plus.isPressed() && dayOfWeek < 7){
			dayOfWeek++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && dayOfWeek > 1){
			dayOfWeek--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
	}

	if(menuCount == 30){
		//set dayOfMonth
		lcd.setCursor(0,0);
		lcd.print("Set Date: Date");
		lcd.setCursor(0,2);
		printDate();
		if(plus.isPressed() && dayOfMonth < 31){
			dayOfMonth++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && dayOfMonth > 1){
			dayOfMonth--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
	}

	if(menuCount == 31){
		//set Month
		lcd.setCursor(0,0);
		lcd.print("Set Date: Month");
		lcd.setCursor(0,2);
		printDate();
		if(plus.isPressed() && month < 12){
			month++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && month > 1){
			month--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
	}

	if(menuCount == 32){
		//set Month
		lcd.setCursor(0,0);
		lcd.print("Set Date: Year");
		lcd.setCursor(0,2);
		printDate();
		if(plus.isPressed() && year < 99){
			year++;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		if(minus.isPressed() && year > 1){
			year--;
			delay(btnCurrDelay(btnCurrIteration-1));
			lcdTime = millis();
		}
		setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
	}

}



Spuzzum is offline   Reply With Quote
Unread 12/13/2011, 07:41 PM   #868
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Uploading the text file of the script just in case. It was "professionally indented" (lol) using Vim in linux.

The reason why the earlier text may have been hard to read.. I use linux, so when a linux text is opened in winblows.. it's all-on-one-line.. so to speak .

Best way to fix that if you should ever come across another file like that.. open it in wordpad, then save as text. Wordpad will understand the formatting .


Also... I should mention I needed to modify "BUTTON" to "BUTTON_PULLDOWN".. script errored out otherwise.. Button.cpp says

Code:
buttonMode == BUTTON_PULLDOWN ? pulldown() : pullup(buttonMode);
Not sure if using Pulldown is the correct thing to do, but like I say.. it errors out otherwise.


Original script:
Code:
// create the buttons
Button menu     = Button(14,BUTTON);
Button select   = Button(15,BUTTON);
Button plus     = Button(16,BUTTON);
Button minus    = Button(17,BUTTON);
Results in:
Code:
sketch_dec13a:97: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:98: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:99: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:100: error: ‘BUTTON’ was not declared in this scope

So i put:
Code:
// create the buttons
Button menu     = Button(14,BUTTON_PULLDOWN);
Button select   = Button(15,BUTTON_PULLDOWN);
Button plus     = Button(16,BUTTON_PULLDOWN);
Button minus    = Button(17,BUTTON_PULLDOWN);
Code:
Done compiling.
Binary sketch size: 21136 bytes (of a 30720 byte maximum)


OK, about the script/mods...

I made the Deuligne version of the i2clcd backpack (shield?). It's based on the LiquidCrystal library, and has the adc_key stuffs already added.. which gives "some" issues if wanting to redefine the keys, as it's already been defined in the *.cpp file. .. Been trying to work with the keys as a base script, but can't for the life of me figure how to say "if the damn up button is pressed.. do this!!" LoL...!

The pinout for the MCP23008's a little different with the Deuligne than the LCDI2C4Bit version DWZM posted in the Hydra thread/design. Just so you know.

The schematics are linked at the top of the script, at snootlab.com. If you click the download tab, you'll see links for schematic, user guide, and all the library stuffs at github.


My next attempt, was to organize the menu items into main/sub menus.. ie: all channel 1 LED settings under 1 main menu heading, then opens to what you want to do in that part of the menu. I was "hoping" to utilize the select button, as it doesn't seem to be used. Maybe use that to "back 1", or "escape/exit"... or something like that. I just found it frustrating to click 28 times just to get back to the previous menu screen.. because I accidentally clicked 1 too many times getting where I wanted... doh!


But as for the adc_key thing... I stripped a key_test script down, and added in a clock.. with date. But like I said.. I can't figure out how to tell the thing what to do if "this" or "that" key is pressed. I figure once I do that.. then I'm on my way to rewriting the entire script from the bottom up.


Code:
/*
 * ADC Key Trials Using the Deuligne Library
 * 
 * For Deuligne i2clcd backpacks - uses the MCP23008 chip
 *
 * Deuligne Schematic:
 * http://shop.snootlab.com/attachment.php?id_attachment=56
 * 
 * Deuligne Library can be foind at github:
 * https://github.com/Snootlab/Deuligne
 *
 * All other files needed at Deuligne's site under the "download" tab:
 * http://shop.snootlab.com/lang-en/powerduino/135-deuligne.html#idTab9
 *
 */

#include  // I2C library include
#include  // LCD library include

Deuligne lcd(0xA7, 16, 4); // lcd object declaration

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// read the buttons
int read_LCD_buttons()
{
	adc_key_in = analogRead(0);      // read the value from the sensor 
	// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
	// we add approx 50 to those values and check to see if we are close
	if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
	if (adc_key_in < 50)   return btnRIGHT;  
	if (adc_key_in < 200)  return btnUP; 
	if (adc_key_in < 400)  return btnDOWN; 
	if (adc_key_in < 600)  return btnLEFT; 
	if (adc_key_in < 800)  return btnSELECT;   
	return btnNONE;  // when all others fail, return this...
}


void setup()
{
	Wire.begin(); // join i2c
	lcd.init(); // LCD init

	lcd.clear(); // Clear Display

	lcd.backLight(true); // Backlight ON

	lcd.setCursor(5,0); // Place cursor row 6, 1st line (counting from 0)
	lcd.print("Setup");
	lcd.setCursor(7,1); // Place cursor row 8, 2nd line (counting from 0)
	lcd.print("ok");
	delay(2000);
	lcd.clear();
	lcd.setCursor(2,0);
	lcd.print("ADC Key Test");
}

void loop() {


	{
		//lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
		//lcd.print(millis()/1000);      // display seconds elapsed since power-up


		lcd.setCursor(0,1);            // move to the begining of the second line
		lcd_key = read_LCD_buttons();  // read the buttons

		switch (lcd_key)               // depending on which button was pushed, we perform an action
		{
			case btnRIGHT:
				{
					lcd.setCursor(5,2);
					lcd.print("RIGHT ");
					delay(1000);
					break;
				}
			case btnLEFT:
				{ 
					lcd.setCursor(5,2);
					lcd.print("LEFT ");
					delay(1000);
					break;
				}
			case btnUP:
				{ 
					lcd.setCursor(5,2);
					lcd.print("UP    ");
					delay(1000);     
					break;
				}
			case btnDOWN:
				{  
					lcd.setCursor(5,2);
					lcd.print("DOWN  ");
					delay(1000);
					break;
				}
			case btnSELECT:
				{
					lcd.setCursor(5,2);
					lcd.print("SELECT");
					delay(1000);
					break;
				}
			case btnNONE:
				{ 
					lcd.setCursor(5,2);  
					lcd.print("NONE  ");
					break;
				}

		}

	}

}
Code:
/*
 * ADC Key Trials Using the Deuligne Library
 * 
 * For Deuligne i2clcd backpacks - uses the MCP23008 chip
 *
 * Deuligne Schematic:
 * http://shop.snootlab.com/attachment.php?id_attachment=56
 * 
 * Deuligne Library can be foind at github:
 * https://github.com/Snootlab/Deuligne
 *
 * All other files needed at Deuligne's site under the "download" tab:
 * http://shop.snootlab.com/lang-en/powerduino/135-deuligne.html#idTab9
 *
 */

#include 
#include  // I2C library include
#include  // LCD library include
#include 

Deuligne lcd(0xA7, 16, 4); // lcd object declaration

#define DEBUG            //compile serial monitor clock display

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// read the buttons
int read_LCD_buttons()
{
	adc_key_in = analogRead(0);      // read the value from the sensor 
	// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
	// we add approx 50 to those values and check to see if we are close
	if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
	if (adc_key_in < 50)   return btnRIGHT;  
	if (adc_key_in < 200)  return btnUP; 
	if (adc_key_in < 400)  return btnDOWN; 
	if (adc_key_in < 600)  return btnLEFT; 
	if (adc_key_in < 800)  return btnSELECT;   
	return btnNONE;  // when all others fail, return this...
}


void setup()
{
	Wire.begin(); // join i2c
	lcd.init(); // LCD init

	Serial.begin(9600);
	RTC.stop();
	RTC.set(DS1307_SEC,1);        //set the seconds
	RTC.set(DS1307_MIN,23);     //set the minutes
	RTC.set(DS1307_HR,12);       //set the hours
	RTC.set(DS1307_DOW,4);       //set the day of the week
	RTC.set(DS1307_DATE,5);       //set the date
	RTC.set(DS1307_MTH,3);        //set the month
	RTC.set(DS1307_YR,9);         //set the year
	RTC.start();

	lcd.clear(); // Clear Display

	lcd.backLight(true); // Backlight ON

	lcd.print("Typhon-Reef");
	lcd.setCursor(0,1);
	lcd.print("");
	delay(5000);
	lcd.clear();
}

void loop() {


	{
		//lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
		//lcd.print(millis()/1000);      // display seconds elapsed since power-up



		lcd.setCursor(0,0);            // move to the begining of the first line
		lcd_key = read_LCD_buttons();  // read the buttons

		lcd.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
		lcd.print(":");
		lcd.print(RTC.get(DS1307_MIN,false));  //read minutes without update (false)
		lcd.print(":");
		lcd.print(RTC.get(DS1307_SEC,false));  //read seconds
		lcd.setCursor(0,1);           // move to the begining of the second line
		switch((DS1307_DOW)){
			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 (DS1307_DATE < 10){
			lcd.print("0");
		}
		lcd.print(RTC.get(DS1307_DATE,false));//read date
		lcd.print("/");
		if (DS1307_MTH < 10){
			lcd.print("0");
		}
		lcd.print(RTC.get(DS1307_MTH,false));//read month
		lcd.print("/");
		lcd.print(RTC.get(DS1307_YR,false)); //read year 
		//  lcd.print();

		delay(1000);

		/*
		   switch (lcd_key)               // depending on which button was pushed, we perform an action
		   {
		   case btnRIGHT:
		   {
		   lcd.setCursor(5,2);
		   lcd.print("RIGHT ");
		   delay(1000);
		   break;
		   }
		   case btnLEFT:
		   { 
		   lcd.setCursor(5,2);
		   lcd.print("LEFT ");
		   delay(1000);
		   break;
		   }
		   case btnUP:
		   { 
		   lcd.setCursor(5,2);
		   lcd.print("UP    ");
		   delay(1000);     
		   break;
		   }
		   case btnDOWN:
		   {  
		   lcd.setCursor(5,2);
		   lcd.print("DOWN  ");
		   delay(1000);
		   break;
		   }
		   case btnSELECT:
		   {
		   lcd.setCursor(5,2);
		   lcd.print("SELECT");
		   delay(1000);
		   break;
		   }
		   case btnNONE:
		   { 
		   lcd.setCursor(5,2);  
		   lcd.print("NONE  ");
		   break;
		   }
		 */    
	}

	}

Enjoy


By the way... if anybody sees how or what I should change to improve my mods.. feel free to mention so. This is my first attempt at c++, so I'm sure it's "messy". I'm more comfortable in DOS.. doesn't take 20 minutes to figure out I needed a "}" at the end of the script



Last edited by Spuzzum; 12/13/2011 at 07:47 PM.
Spuzzum is offline   Reply With Quote
Unread 12/13/2011, 08:45 PM   #869
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
lol! Just discovered something that I've only looked at about 50 times now...

Code:
int a=0;

void setup()

a==0  (Up_Key);     // "Up"
a==1  (Down_Key);   // "Down"
a==2  (Left_Key);   // "Left", "+"
a==3  (Right_Key);  // "Right", "-"
a==4  (Select_Key); // "Select"


void loop()

  a=lcd.get_key();
  if (a==4) // someone pressed 'enter'

NOW it makes sense...


Spuzzum is offline   Reply With Quote
Unread 12/14/2011, 06:55 AM   #870
Megablue
Registered Member
 
Join Date: Aug 2009
Location: France
Posts: 14
Quote:
Originally Posted by der_wille_zur_macht View Post
You guys are thinking way too complicated for what he's trying to achieve.

Set up the free pin as a one-wire port. You now have one-wire, I2C, and serial available. Put a DS18B20 on the one-wire port and use it to sense temperature. Find a dedicated fan controller IC (or a generic PWM generator) that can work on one-wire or I2C and use that to control the fan.
Or use the modified board
[IMG]http://i43.*******.com/2m3k2zl.jpg[/IMG]

1wire buttons, 2x lm35 temp, 1 pwm fan, and the four led channels.


Megablue is offline   Reply With Quote
Unread 12/14/2011, 07:40 AM   #871
shark boy
Registered Member
 
shark boy's Avatar
 
Join Date: Jul 2011
Posts: 118
As my grandpa would say.

Now we're cooking with gas!!! LOL


shark boy is offline   Reply With Quote
Unread 12/14/2011, 09:55 AM   #872
zero2007
Registered Member
 
Join Date: Jun 2011
Posts: 8
Quote:
Originally Posted by Spuzzum View Post


Also... I should mention I needed to modify "BUTTON" to "BUTTON_PULLDOWN".. script errored out otherwise.. Button.cpp says

Code:
buttonMode == BUTTON_PULLDOWN ? pulldown() : pullup(buttonMode);
Not sure if using Pulldown is the correct thing to do, but like I say.. it errors out otherwise.


Original script:
Code:
// create the buttons
Button menu     = Button(14,BUTTON);
Button select   = Button(15,BUTTON);
Button plus     = Button(16,BUTTON);
Button minus    = Button(17,BUTTON);
Results in:
Code:
sketch_dec13a:97: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:98: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:99: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:100: error: ‘BUTTON’ was not declared in this scope

So i put:
Code:
// create the buttons
Button menu     = Button(14,BUTTON_PULLDOWN);
Button select   = Button(15,BUTTON_PULLDOWN);
Button plus     = Button(16,BUTTON_PULLDOWN);
Button minus    = Button(17,BUTTON_PULLDOWN);
Code:
Done compiling.
Binary sketch size: 21136 bytes (of a 30720 byte maximum)


I changed #include Button.h to #include

that enabled me to use:

Original script:
Code:
// create the buttons
Button menu     = Button(14);
Button select   = Button(15);
Button plus     = Button(16);
Button minus    = Button(1);
Also I changed EEPROMVar to EEPROMVar

Then it compiled fine for me.
Thanks

Zero


zero2007 is offline   Reply With Quote
Unread 12/14/2011, 10:10 AM   #873
zero2007
Registered Member
 
Join Date: Jun 2011
Posts: 8
Quote:
Originally Posted by Spuzzum View Post


Also... I should mention I needed to modify "BUTTON" to "BUTTON_PULLDOWN".. script errored out otherwise.. Button.cpp says

Code:
buttonMode == BUTTON_PULLDOWN ? pulldown() : pullup(buttonMode);
Not sure if using Pulldown is the correct thing to do, but like I say.. it errors out otherwise.


Original script:
Code:
// create the buttons
Button menu     = Button(14,BUTTON);
Button select   = Button(15,BUTTON);
Button plus     = Button(16,BUTTON);
Button minus    = Button(17,BUTTON);
Results in:
Code:
sketch_dec13a:97: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:98: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:99: error: ‘BUTTON’ was not declared in this scope
sketch_dec13a:100: error: ‘BUTTON’ was not declared in this scope

So i put:
Code:
// create the buttons
Button menu     = Button(14,BUTTON_PULLDOWN);
Button select   = Button(15,BUTTON_PULLDOWN);
Button plus     = Button(16,BUTTON_PULLDOWN);
Button minus    = Button(17,BUTTON_PULLDOWN);
Code:
Done compiling.
Binary sketch size: 21136 bytes (of a 30720 byte maximum)


I changed
Code:
#include Button.h to

 #include Button.h
with < and > at either end of button
that enabled me to use:

Original script:
Code:
// create the buttons
Button menu     = Button(14);
Button select   = Button(15);
Button plus     = Button(16);
Button minus    = Button(17);
Also I changed EEPROMVar to EEPROMVar
Then it compiled fine for me.
Thanks

Zero


zero2007 is offline   Reply With Quote
Unread 12/14/2011, 10:58 AM   #874
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Ok.. I just realized something... using the code tags doesn't display the code correctly here in the thread. All the "#include " actually does have the "< >" symbols when I posted it.

It "should" be showing:

Code:
// include the libraries:
#include "Deuligne.h"
#include "Wire.h"
#include "Button.h"
#include "EEPROM.h"
#include "EEPROMVar.h"
But with < > instead of " "


And as for the Button.h... doesn't matter if in < > or " " .. it still errors if using:

Code:
// create the buttons
Button menu     = Button(14,BUTTON);
Button select   = Button(15,BUTTON);
Button plus     = Button(16,BUTTON);
Button minus    = Button(17,BUTTON);

It may just be my copy/version of the Button library. It could also be a linux thing.. it's not as lenient as winblows.



So I tried making sub menus last night. The script already has "menuSelect" happening in the (menuCount == 2). So I figured I'd start with "channel 1".. rewrote so the menuSelect will cycle through start time, end time, fade duration, and max intensity settings. It worked.. but only for the first 4 menuSelects I used.

The script is set for 4 choices of menuSelect, so I didn't go over the limit:

Code:
if(menuSelect < 3){menuSelect++;}
else{menuSelect = 0;}

But if I add the channel 2 stuffs to the next menuChoice/menuSelect portion.. I can scroll through channel 1 menu, but press menu again to go to channel 2 menu.. the screen blanks out for 5 seconds or so, then finally goes back to the main screen. Obviously not what I want to achieve .

Not sure if the total # of menuSelect needs to be specified somewhere else, or just the # of menuSelect per menuChoice, specified within that menuchoice.


Spuzzum is offline   Reply With Quote
Unread 12/14/2011, 03:14 PM   #875
Spuzzum
Registered Member
 
Join Date: Feb 2011
Posts: 70
Found my error with the sub menu... was forgetting to add " } " at the ends of each group of submenus.. instead I just added at the end of the script when the compiler prompted me for a squiggly


Just remove the .txt at the end of the file name, and open in Arduino.

All LED options are in their own main menu, with each individual option (4) cycled by the select button.. ie: button "right".

Time is in it's own menu with just the 2 options, and date is in it's own menu as well with it's 4 options.

To go to the next menu.. the menu button.. "left".


Other than that.. it's still the same script. I just cut and pasted from the original, but sectioned it out.. and modified the total menu count to the new number of menus. Doesn't show menu 10 if it's only stated as 9 menus in total... took about an hour to figure that one out .


Attached Files
File Type: txt typhon_w_date_and_submenus.pde.txt (33.9 KB, 115 views)
Spuzzum is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cheap Moonlight ticklesworth New to the Hobby 3 04/04/2010 04:09 PM
Cheap Moonlight ticklesworth Do It Yourself 0 04/03/2010 08:52 AM
Arduino base controller - power pack ONLY TODAY MaLi Do It Yourself 0 03/07/2010 05:56 AM
Sumps 101: Cheap, simple and effective for small tanks cody6766 Central Oklahoma Marine Aquarium Society 8 01/06/2009 10:57 AM


All times are GMT -6. The time now is 12:03 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Powered by Searchlight © 2024 Axivo Inc.
Use of this web site is subject to the terms and conditions described in the user agreement.
Reef CentralTM Reef Central, LLC. Copyright ©1999-2022
User Alert System provided by Advanced User Tagging v3.3.0 (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.