I'm not a programmer, due to which I have combined various sections of code others have written.
The code below allows for my marine reef aquarium to be automated to a degree, allowing for what appears to the naked eye as a smooth fade transition between lighting stages, based on the time stamp provided by an RTC. In addition to this, it will variate 2 water pump channels with the intent to allow for irregular water current movements.
My issue today is that my led channels only have two stages; night and day. I really wish for a 3rd stage to be incorporated into this design..
Stage 1; blues at 0%, whites creep up over an hour or so to 100% (0930 am)
Stage 2; blues increase to say 50%, white fades back to 10% (1530pm)
Stage 3; Blue fades back to 5% and whites fade to 0% (2245pm)
Further to this, I am having issues with my 5110 lcd display and printing an accurate time to it, time appears to be all over the place on 5110 however is stamping accurately in serial.
I appreciate that this is a fair chunk of code and I thank anyone who can give me support with this.
Stage 1; blues at 0%, whites creep up over an hour or so to 100% (0930 am)
Stage 2; blues increase to say 50%, white fades back to 10% (1530pm)
Stage 3; Blue fades back to 5% and whites fade to 0% (2245pm)
You are describing a state machine with 3 states. Currently you have 2 states which is easily handled with if/else because you want one of two things to be happening.
You can code 3 states using if/else if/else and test the time but to my mind that gets messy and it is better (in my opinion) to use switch/case as it makes the code easier to read, for me at least.
Each time through loop() derive the current state, lets call it fadeState and value it 0, 1 or 2 depending on the time of day
Then use switch(fadeState) to execute the correct portion of code for the current state. Job done.
Incidentally, reading some, but not all of your code I saw some things worthy of comment.
Why are you using seconds since midnight when you could use the current time directly ?
A small thing at the moment but it could bite you if you begin to run out of memory but in
const int kChan0Pin = 9; // Channel 0 Pin
const int kChan1Pin = 10; // Channel 1 Pin
const int pump1 = 5; // pump 1
const int pump2 = 13; // pump 2
int buttonPin = 2; // button to pin 2
int buttonPushCounter = 0; // counter for amount of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of button
the variables could be declared as bytes to save space.
Check whether Serial.flush(); // ensure we never have more than 5 bytes bufferedis actually doing what you think and if not, remove it.
The reason why I'm using minutes past midnight is simply because the author of the original sunrise/sunset control code designed it that way and I don't have the necessary skills to convert it..
Ideally I would like it to be defined simply by a 24hr clock numeric not minutes past midnight.
I'm a tad uncertain how to convert this to a state machine using the fade method that the original author wrote.
Again, I really appreciate the support that you or anyone else could provide as I said I'm not that familiar with writing code.
as I said I'm not that familiar with writing code.
What is your purpose in doing this project, then? Why choose a project that involves programming if it isn't to learn to program?
If i did not intent to learn, I would not be on here learning.. The atmega chipset, as I'm sure your aware of, allows for complex control of systems which otherwise could not be automated in such a way. This application (marine fish tank) is my second functional build using an arduino, and hence, I am very new and find code unfamiliar.
The peer support and guidance available through sites like this really underpin the open-source nature of this and I assume novices are welcomed, without nature of questioning I find to be subjective and off subject PaulS.
as I said I'm not that familiar with writing code.
What is your purpose in doing this project, then? Why choose a project that involves programming if it isn't to learn to program?
If i did not intent to learn, I would not be on here learning.. The atmega chipset, as I'm sure your aware of, allows for complex control of systems which otherwise could not be automated in such a way. This application (marine fish tank) is my second functional build using an arduino, and hence, I am very new and find code unfamiliar.
The peer support and guidance available through sites like this really underpin the open-source nature of this and I assume novices are welcomed, without nature of questioning I find to be subjective and off subject PaulS.
You are entitled to your opinions, and are free to consider my question offensive.
It wasn't meant to be. If you really are interested in learning, you would not keep repeating that you aren't a programmer.
It's that repetition and attitude that goes with it ("I don't know how to do that; can you write the code for me?") that bothers me.
PaulS, I believe you are trolling this thread and filling it with unrelated accusations and opinions. May I advise when people ask for guidance, if you do not intent to guide them, then just leave their thread alone.