Who wants a cheap, simple, Arduino-based LED controller?

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);
}
 
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
 
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
 
Sorry... had to split it up.. can't post all as 1 :p

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 <Deuligne.h>
#include <Wire.h>
#include <Button.h>
#include <EEPROM.h>
#include <EEPROMVar.h>

// 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<int> oneStartMins = 750;      // 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 = 60;   // duration of the fade on and off for sunrise and sunset for
//    this channel.
EEPROMVar<int> twoStartMins = 810;
EEPROMVar<int> twoPhotoPeriod = 600;
EEPROMVar<int> twoMax = 100;
EEPROMVar<int> twoFadeDuration = 60;

EEPROMVar<int> threeStartMins = 810;
EEPROMVar<int> threePhotoPeriod = 600;
EEPROMVar<int> threeMax = 100;
EEPROMVar<int> threeFadeDuration = 60;

EEPROMVar<int> fourStartMins = 480;
EEPROMVar<int> fourPhotoPeriod = 510;  
EEPROMVar<int> fourMax = 100;          
EEPROMVar<int> fourFadeDuration = 60;  

EEPROMVar<int> fiveStartMins = 480;
EEPROMVar<int> fivePhotoPeriod = 510;  
EEPROMVar<int> fiveMax = 100;          
EEPROMVar<int> fiveFadeDuration = 60;  

EEPROMVar<int> sixStartMins = 480;
EEPROMVar<int> sixPhotoPeriod = 510;  
EEPROMVar<int> sixMax = 100;          
EEPROMVar<int> 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;
 
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));
}
 
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);
	}

}
 
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 :p.

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 <Wire.h> // I2C library include
#include <Deuligne.h> // 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 <WProgram.h>
#include <Wire.h> // I2C library include
#include <Deuligne.h> // LCD library include
#include <DS1307.h>

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 :p
 
Last edited:
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... :D
 
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
2m3k2zl.jpg


1wire buttons, 2x lm35 temp, 1 pwm fan, and the four led channels.
 
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 <Button.h>

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<int>

Then it compiled fine for me.:cool:
Thanks

Zero
 
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<int>
Then it compiled fine for me.:cool:
Thanks

Zero
 
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 :p.

Not sure if the total # of menuSelect needs to be specified somewhere else, or just the # of menuSelect per menuChoice, specified within that menuchoice.
 
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 :p


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 :p.
 

Attachments

hi guys the title of the draws my attention i just started to get into this diy controller for aquariums. i don't want any fancy temperature sensing things for now just wanted to have a simple LED fade in and out controller after spending couples of hour for the past few days reading through the post on this topics it kinda out of my league XD building an arduino. i do have some background in coding but a total noob in circuits XD. i google around and got two "constant current regulator with pwm dimming" supposly it converts regular current from a switch mode power supple to a constant current. and some leds for testing. and this is what i got so far
img0138xy.jpg

img0149zl.jpg

the result was pretty good. took me a few hours to figure out arduino coding and now i got an simple fade in and out effect with a for loop so the code in this post is gonna help me a lot.

btw i wanna ask if anybody know why when i use pin 13 on the arduino the red led on is on solid. i have my rtc connect to pin 13 so if anybody can tell me i will be greatly appreciate it. and The led i use is 1 strip Cree XR-E Q5+D5 and the other one is an generic type of led i got both to compare them. if i remember correctly i saw it in a another post before and finally found them :)
 
btw i wanna ask if anybody know why when i use pin 13 on the arduino the red led on is on solid. i have my rtc connect to pin 13 so if anybody can tell me i will be greatly appreciate it.


Very nice :).

The pin13 LED is the activity LED on the arduino itself. This is to verify activity when the atmel's being flashed/programmed. But since it's wired directly in the circuit, there's no way of turning it off if using the pin for something else. Only option.. would be to cut the trace of the led coming off the ground side, and wire in a switch to enable it again if you want that verification option. That's only if the LED's going to be bothersome to look at.. if not, then just leave as be.

I say the ground side, as I'm not sure about the trace coming off the pin itself.. that may lead to the connector sockets.
 
By the way.. just came across something at the arduino playground. I mentioned earlier about using a 128 or 256kb i2c eeprom, for more memory storage.. freeing up the 328 for the actual program functions. Well here ya go...

Using Arduino with an I2C EEPROM


I got my hands on an AT24C256 (256 kbit = 32 kbyte serial EEPROM). I found no library for it, so I created a small sketch with few functions to show how the i2c_eeprom_write_page and i2c_eeprom_read_byte functions work.


Because this chip is I2C, it only uses the analog pins 4 & 5 (SDA and SCL), and of course the power (5V) and GND.


Connect as follows:


Arduino pin 4 to EEPROM pin 5
Arduino pin 5 to EEPROM pin 6
Arduino 5V to EEPROM pin 8
Arduino GND to EEPROM pin 1,2,3,4


Be sure to leave pin 7 of the EEPROM open or tie it to GND otherwise the EEPROM will be write protected.


Just a few quick functions for reading/writing the EEPROM (not a library, yet). 'deviceaddress' refers to the EEPROM I2C address, eg. 0x50.

Code:
 /* 
  *  Use the I2C bus with EEPROM 24LC64 
  *  Sketch:    eeprom.pde
  *  
  *  Author: hkhijhe
  *  Date: 01/10/2010
  * 
  *   
  */

  #include "Wire.h" //I2C library



  void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
    int rdata = data;
    Wire.beginTransmission(deviceaddress);
    Wire.send((int)(eeaddress >> 8)); // MSB
    Wire.send((int)(eeaddress & 0xFF)); // LSB
    Wire.send(rdata);
    Wire.endTransmission();
  }

  // WARNING: address is a page address, 6-bit end will wrap around
  // also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
  void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.send((int)(eeaddresspage >> 8)); // MSB
    Wire.send((int)(eeaddresspage & 0xFF)); // LSB
    byte c;
    for ( c = 0; c < length; c++)
      Wire.send(data[c]);
    Wire.endTransmission();
  }

  byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
    byte rdata = 0xFF;
    Wire.beginTransmission(deviceaddress);
    Wire.send((int)(eeaddress >> 8)); // MSB
    Wire.send((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,1);
    if (Wire.available()) rdata = Wire.receive();
    return rdata;
  }

  // maybe let's not read more than 30 or 32 bytes at a time!
  void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.send((int)(eeaddress >> 8)); // MSB
    Wire.send((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,length);
    int c = 0;
    for ( c = 0; c < length; c++ )
      if (Wire.available()) buffer[c] = Wire.receive();
  }




  void setup() 
  {
    char somedata[] = "this is data from the eeprom"; // data to write
    Wire.begin(); // initialise the connection
    Serial.begin(9600);
    i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM 

    delay(10); //add a small delay

    Serial.println("Memory written");
  }

  void loop() 
  {
    int addr=0; //first address
    byte b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory

    while (b!=0) 
    {
      Serial.print((char)b); //print content to serial port
      addr++; //increase address
      b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
    }
    Serial.println(" ");
    delay(2000);

  }


http://www.arduino.cc/playground/Code/I2CEEPROM
 
My Build

My Build

Here are the fruits of my DIY labor. Many thanks to everyone here that contributed to the Typhon Reef sketch, and shared there own DIY knowledge. My new Light is much sexier than it would have been without all your help!

There are 96 Luxeon Rebel emitters on 32 three-up stars 20mm in diameter. Each star has a Neutral White, Blue and Royal Blue. Mixing is basically perfect because the LEDs are so close to one another.
6518021203_0c9d7ef698_z.jpg


6518020079_fb4cc93c56_z.jpg


The controller is built into an old Pelican case I've had sitting around. It's a tad overbuilt hehe.
6518020223_a2ffff194b_z.jpg


6518020561_c5c3b4eeba_z.jpg


6518020417_0fc18d2d8f_z.jpg


6518021095_422d2c376b_z.jpg
 
Back
Top