A little bit of code help needed *Warning I'm A Noob*

Hey! Thanks for reading!
Just started to get back into arduino and my electronics so, excuse my beginner questions.
My last post was getting some LEDs for my fish tank. I basically have some LED strips being powered by the arduino at different times of the day. Don't worry that I mentioned fish tank, these are all arduino questions, nothing about fish. :slight_smile:
Ok, this is the code I was gonna use for it.
I basically just modified the blink sketch, nothing fancy.

int dayled= 12; //Define white LED strip as pin 12
int nightled= 11; //Define blue LED as pin 11

void setup() {
pinMode(dayled, OUTPUT);
pinMode(nightled, OUTPUT);
}

void loop() {
digitalWrite(dayled, HIGH); //Define brightness of White led as on
delay(54000000); //Wait in Milliseconds
digitalWrite(dayled, LOW); //Define brightness of White led as off
digitalWrite(nightled, HIGH);//Define brightneess of Blue leds as on
delay(32400000);
digitalWrite(nightled, LOW); //Define brightness of Blue leds as off
}

I have 2 different LEDs, some white ones for the day, and then some blue ones for night.
I have them hooked up by a MOSFET. I have 2 MOSFETS, 1 for the white LEDs, and another for the blue. I used this diagram to wire everything. I attached it below.
The LEDs are powered off a 12 volt 2 amp wall wart.
Ok, so that is what the pin 12 and 11 go to.

Buttttt here are my questions.

I would love to have a pot to fade the brightness of the LEDs, one for both LEDs would be great.

Next, I would like to have a SPST switch that I can hit and turn the LED strips off. Now, I know its possible to have this just on the output line from the arduino to the LED, but I would prefer doing it from the arduino since I am already using it. I always make it more complicated. Lol. This switch I would like to be just like a master switch, so whether the night LEDs (Blue) or the day LEDs (White) are on, they will turn off until I hit the switch again. I would like for it to be a Push Button Momentary Switch, but if a simple toggle switch would be easier, thats fine.

Also, is it possible instead of using the delay function, but to set like a arduino clock? That way the arduino counts like a clock, so I could say "Turn of White LEDs at 4" or something similar. Or the arduino could see that it is Saturday, so don't give power to the lights for another 3 hours.

Wow. That was a lot....
Guys I am super happy that you read this, and that you are willing to help me!

If you put your code inside code tags it's easier for us to read.
It's the # button, next to the quotes in your reply.

You have to hit the "preview" button to see all the fancy formatting buttons like the code # button.

Forget that stupid "Blink" sketch. This is why I hate that they start teaching us newbies to use "delay()". Without using something like interrupts, you can't easily fade an LED during a delay().

Go into the second Examples folder, Digital, and open "Blink Without Delay".

There is a mistake in there.... Change this:

long previousMillis = 0;        // will store last time LED was updated

Into this:

unsigned long previousMillis = 0;        // will store last time LED was updated

Now what happens:

millis() is a timer that starts counting milliseconds since the Arduino was last reset. That little fix above makes it so it keeps working even when it rolls over. The variable "interval" sets the length in milliseconds between turning the LED on or off.

You'll want to modify this to your purposes. It appears you want the white LED on for 15 hours, and the blue LED on for 9 hours. Easiest but not the most convenient way to set this for a start time is to have it begin when you reset the Arduino, and just reset it when you want the white LED to start.

I've given you a start. It is late, and I am tired, and I am also a newbie at programming Arduinos.

Um... and you need to use PWM to dim the LEDs. Which means you'll need to use analog pins and use analogWrite() to output to the LEDs.

Look in the third Example folder, Communication, for the sketch "Dimmer".

Toggle switch, push-on-push-off, or momentary switch? The first two are easy to implement. You can get,them at radioshack.
To do real human time, you need a real time clock, such as ds1307 chip.

i am just asking myself what kind of led you use? 60V for a few leds seems a lot to me... :blush:

Momentary switch I would like. But forget it because I am just gonna run it inline with the LEDs, not as cool as using the arduino but it is simpler. Also, they LEDs aren't using 60v. That's what could go in. Like I said, they use 12v.
Thanks for the help so far.

To use a momentary switch, you need to detect the "press", which is a transition from not depressed to depressed, say from logical HIGH to logical LOW. You can't just read the current logical level and determine a press. You need to read and store the current logical level, and then read again (repeatedly) and compare with stored. If stored is not depressed and current reading is depressed, you have a click.

I'm working on a arduino based light controller for an aquarium as well. Didn't see this thread until after I posted a new thread.

While my method for getting the lights on and off are different than yours, my code may offer some help.

I have implemented fading on the lights, lighting schedule, manual override, sunrise/sunset timing, and power loss recovery. You may be able to implement some of the code for your needs.

http://forum.arduino.cc/index.php?topic=219680.0

Thanks ^^^ .
I have used your code, just slightly modified it to run 2 different sets of lights. 1 during the day and 1 during the night, moonlight and they day lights assist my fluorescent tube. Thanks guys. Still waiting for a few parts, mainly the LED strip power supply.
But yea...
Adios