Another Arduino LED light schedule sketch - Page 4 - The Planted Tank Forum
 2Likes
Reply
 
LinkBack Thread Tools Display Modes
post #46 of 100 (permalink) Old 12-02-2013, 08:00 AM Thread Starter
Algae Grower
 
benjaf's Avatar
 
Join Date: Mar 2012
Location: Denmark
Posts: 111
Just read through your build thread - damn, suddenly I'm really appreciating dealing with a small low-tech planted tank! No PH probes with grounding issues, no massive LED driver arrays to burn. Oh, and no touchscreen!
Learning Python and using Qt for GUI is somewhat more forgiving.
Congratulations on getting this far, I'm confident you will be able to complete it at some point

// Benjamin
benjaf is offline  
Sponsored Links
Advertisement
 
post #47 of 100 (permalink) Old 12-09-2013, 02:56 AM
Algae Grower
 
Join Date: Dec 2012
Location: Okeechobee, FL
Posts: 12
Thanks for putting this code out there for us!

I'm having a problem that I hope someone can clarify. I would like to have the lights intensify to some medium value (here 150) between 0800 and 1000, then have a midday burst at full intensity from 1200 to 1400 followed by another period of medium intensity from 1500 to 1930 and finally a fade out from 1930 to 2130. With the following schedule the lights go out (0 intensity) at 14:00 and then come back up to 150 at 1500.

// Channel 0:
Channels[0].Pin = 11;
Channels[0].AddPoint(8, 0, 0);
Channels[0].AddPoint(10, 0, 150);
Channels[0].AddPoint(12, 0, 255);
Channels[0].AddPoint(14, 0, 255); Lights go out here instead of fading down
Channels[0].AddPoint(15, 0, 150);
Channels[0].AddPoint(19, 30, 150);
Channels[0].AddPoint(21, 30, 0);

How am I coding this wrong?
coonass is offline  
post #48 of 100 (permalink) Old 12-09-2013, 08:46 PM Thread Starter
Algae Grower
 
benjaf's Avatar
 
Join Date: Mar 2012
Location: Denmark
Posts: 111
Well that part looks fine, so my only other guess would be that you have MaxPoints set too low? If that's not the problem it's possible there may be a bug in the intensity calculation.
Does the light come on again after turning off, or does it just stay off?
benjaf is offline  
post #49 of 100 (permalink) Old 12-09-2013, 11:01 PM
Algae Grower
 
Join Date: Dec 2012
Location: Okeechobee, FL
Posts: 12
The lights come back on. From 1400 to 1500 they fade from 0-150 rather than from 255-150.

MaxPoints = 10
coonass is offline  
post #50 of 100 (permalink) Old 12-10-2013, 05:08 AM Thread Starter
Algae Grower
 
benjaf's Avatar
 
Join Date: Mar 2012
Location: Denmark
Posts: 111
Odd.. I'll try to replicate it and find out why that happens!
benjaf is offline  
post #51 of 100 (permalink) Old 12-10-2013, 09:01 AM Thread Starter
Algae Grower
 
benjaf's Avatar
 
Join Date: Mar 2012
Location: Denmark
Posts: 111
After a quick review I have updated the code.
The old version had several bugs in the intensity calculation, so I have merged the 'old' public version and parts of my experimental branch. This means a few changes will have to be made to fit this in to your code, but I believe the benefits are worth some minor changes.

Major differences:
* Channel boilerplate code moved to a library to reduce mess
* Channels are initialized slightly differently
* A 'Points' array must be defined along with 'Channels'
* You can now choose between linear and exponential fading
* Intensity can be defined as integer (0 - 255) or float (0 - 1), but is handled as a float internally
benjaf is offline  
post #52 of 100 (permalink) Old 12-10-2013, 11:15 AM
Algae Grower
 
Join Date: Dec 2012
Location: Okeechobee, FL
Posts: 12
I am going out of town for the rest of the week. I'll give this another try on Friday and report back.
coonass is offline  
post #53 of 100 (permalink) Old 12-30-2013, 09:31 PM
Newbie
 
Join Date: Dec 2013
Location: Sweden
Posts: 2
I've looked at this code and it fits my array the most.
Like the idea of "low tech" arduino controlling without LCD displays and so on.
I just need 4 channels and a way to set the starting times... (can't really make sense off the code) I'm pretty noob to this programming bit...

lateron i'm thinking of adding a thunder storm and so on...
can some of you help with the code of adding 2 more channels?
and mabye help me understand the code.
if I want PWM 180 to be 100% and not PWM 255...
Pady is offline  
post #54 of 100 (permalink) Old 12-31-2013, 10:52 AM Thread Starter
Algae Grower
 
benjaf's Avatar
 
Join Date: Mar 2012
Location: Denmark
Posts: 111
So just to be sure I got this right before the examples..
You currently want the following:

4 channels
Simple sunrise / sunset for all channels
Max intensity of ~180

To get 4 channels you have to do the following:
Change this:
Code:
const int MaxChannels = 2;
to this:
Code:
const int MaxChannels = 4;
If all you need is simple sunrise / sunset, you don't need more than 4 points in each channel. So you can safely set MaxPoints to 4 in stead of 10:
Code:
const int MaxPoints = 4;
Then you need to set up the schedules for each channel.
Change the pin / times / intensities in Channel 0 to fit your schedule, and then replace this:
Code:
        // Channel 1:
        channelNo = 1;        // Currently editing channel 1
        pin = 11;                // Channel 1 uses pin 11
        Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
        Channels[channelNo].AddPoint(8, 0, 0);
        Channels[channelNo].AddPoint(8, 30, 150);
        Channels[channelNo].AddPoint(11, 0, 255);
        Channels[channelNo].AddPoint(11, 15, 0);
        Channels[channelNo].AddPoint(12, 30, 0);
        Channels[channelNo].AddPoint(12, 45, 255);
        Channels[channelNo].AddPoint(19, 30, 150);
        Channels[channelNo].AddPoint(20, 0, 0);
with the following (set the correct pins / times / intensities to match your setup):
Code:
        // Channel 1:
        channelNo = 1;        // Currently editing channel 1
        pin = 11;                // Channel 1 uses pin 11
        Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
        Channels[channelNo].AddPoint(8, 0, 0); // 08:00 - Intensity = 0
        Channels[channelNo].AddPoint(8, 30, 180); // 08:30 - Intensity = 180 
        Channels[channelNo].AddPoint(19, 30, 180); // 19:30 - Intensity = 180
        Channels[channelNo].AddPoint(20, 0, 0); // 20:00 - Intensity = 0
		
	// Channel 2:
        channelNo = 2;        // Currently editing channel 2
	pin = 9;                // Channel 2 uses pin 9
        Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
        Channels[channelNo].AddPoint(8, 0, 0);
        Channels[channelNo].AddPoint(8, 30, 180);
        Channels[channelNo].AddPoint(19, 30, 180);
        Channels[channelNo].AddPoint(20, 0, 0);
		
		// Channel 3:
        channelNo = 3;        // Currently editing channel 3
        pin = 6;                // Channel 3 uses pin 6
        Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
        Channels[channelNo].AddPoint(8, 0, 0);
        Channels[channelNo].AddPoint(8, 30, 180);
        Channels[channelNo].AddPoint(19, 30, 180);
        Channels[channelNo].AddPoint(20, 0, 0);
What you just did by altering and inserting the above, is to configure channels 0 - 3. No more code needs to be changed, now you have a complete 4-channel setup.

The rest of the code (in the main sketch at least) is quite straightforward. Every loop checks if a second has passed since last time the lights were updated, and then calculates the current intensity levels for each channel.
benjaf is offline  
post #55 of 100 (permalink) Old 01-10-2014, 06:40 PM
Planted Tank Obsessed
 
HunterX's Avatar
 
Join Date: May 2012
Location: Springfield MO
Posts: 394
Ben,

Love the light code mate . I doing some comparison with some other light codes to see about working in the storm stuff.

Do you know if scapegoat's wiki is still up? I clicked on the link and page was not available. Thanks again. Great work!
HunterX is offline  
post #56 of 100 (permalink) Old 01-10-2014, 07:44 PM Thread Starter
Algae Grower
 
benjaf's Avatar
 
Join Date: Mar 2012
Location: Denmark
Posts: 111
Quote:
Originally Posted by HunterX View Post
Ben,

Love the light code mate . I doing some comparison with some other light codes to see about working in the storm stuff.

Do you know if scapegoat's wiki is still up? I clicked on the link and page was not available. Thanks again. Great work!
Thanks!
You will probably need to make a few changes to enable an 'effect' overlay, but it should be possible.

I think he made some breaking changes to the wiki. Last time I saw it there was some stuff about CO2 and then my code. I think he had trouble getting people to submit content.
benjaf is offline  
post #57 of 100 (permalink) Old 01-17-2014, 03:26 AM
Algae Grower
 
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Hi Benjaf...yep it's me again.

Just having an issue I can't seem to sort, and was hoping you could nudge me in the right direction.

Long story short I am having difficulties with the ramping up of the LEDs. This started happening when I had to undo your nice tidy array in order to integrate my UI.
What is happening is the increasing intensity of the LEDs has become jerky. It ramps up in steps rather than the nice smooth increase from 0 to the max LED vlaue.
Just a rough example...the LEDs come on at about 20%, 40% a few seconds later, and so on. Noticeable increase to the eye.

I've been trying to figure out why this is happening, and correct the issue for some time now, and finally had to bother you yet again.

Funny thing is nothing else is effected. Timing schedules for all the periods is correct with no issues, and the fading from max led value to 0 is still silky smooth.

Do you have any idea what might be causing this?
I could send my code if you need.

Thanks again!
AquaPorn is offline  
post #58 of 100 (permalink) Old 01-17-2014, 05:15 AM Thread Starter
Algae Grower
 
benjaf's Avatar
 
Join Date: Mar 2012
Location: Denmark
Posts: 111
Hello again Steve!
That does sound very strange, if you send me your code I will have a look at it as soon as I can.
benjaf is offline  
post #59 of 100 (permalink) Old 01-17-2014, 02:35 PM
Algae Grower
 
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Thanks for taking a look!

Hopefully you can make heads or tails of it....I try to be neat, but it doesnt always work out.

Last edited by AquaPorn; 01-18-2014 at 05:45 PM. Reason: Remove file
AquaPorn is offline  
post #60 of 100 (permalink) Old 01-17-2014, 05:50 PM Thread Starter
Algae Grower
 
benjaf's Avatar
 
Join Date: Mar 2012
Location: Denmark
Posts: 111
That's a lot of code!
I'll take a closer look when I have a bit of time.
benjaf is offline  
Reply

Tags
arduino, diy, led

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the The Planted Tank Forum forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in









Human Verification

In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.



Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may 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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On

 
For the best viewing experience please update your browser to Google Chrome