In an ideal world yes, it would be logical to save those values for the future.
Attached is Version 6.00
ChickenCoopAllenV6.00.ino (29 KB)
This is great,
I have been working away here getting my head around it all. I was up to adding in menus for the settings and was wondering if you do the menus as different Machine States or keep them outside of the machine state. In my mind it was outside, as the "machine" was still in the same state but it depends if you look at the machine as the output of the programming or the machine is the programming itself. I see your menus are within the checkSwitches() so they are outside.
To use an analogy from the old DOS game Zork
If you are in the library (machine State = library) and "get book" then "read book" are you still in the library state and just doing something (perfoming a function) or are you now in a new state (machine state = reading book) or are you in a substate of Library if a substate is such a thing.
I have been using your sketch to learn so have been hacking it around and have
#ifdef Testing
Ellapsed = millis() - duskMillis;
countDown = ((duskDelay - Ellapsed) / 1000);
#else
Ellapsed = millis() - duskMillis;
countDown = ((duskDelay - Ellapsed) / 60000);
#endif
so I can display the countdown in seconds during testing or minutes when not testing, seems to work
I have also set the timing variables between a
#ifdef Testing and an #else so I only have to comment out the #define Testing
I think a timeout would be beneficial to the switch case when editing values so it returns to automatic after 20 secs?.
Also picked up in the commented out time delays a Lnog which should be a long
const unsigned lnog resettingDelay = 2 * 1000ul; //2 seconds
20 second 'Settings timeout' added.
Version 6.10 attached
Any questions to this point ?
Oops, I think I gave the wrong version, I'll try again.
Here is Version 6.10 timeout added.
ChickenCoopAllenV6.10.ino (30.7 KB)
I have many questions but having code that does exactly what I need is allowing me to figure out exactly how it works to achieve the result rather than taking some other code and then trying to apply bits of it. While that can be a awy to learn it can be hit and miss.
I suppose the biggest question is why you have spent so much time helping me
I'm sure there are bigger and more rewarding projects out there to tackle than an automatic door for for the 5 Orpington Chickens of Coalgate.
I'm just working through what you have done.
I was struggling with how you got the switch case to work for the menu buttons but I think I've worked it out that the line in Case Automatic "modeSwitchState = Manual;" that then sets the case for the next time the button is pushed for 1 second using the "switch (modeSwitchState)" which would now return the case for Switch(Manual)
One very basic question, almost embarrassing to ask, is in the code, for example
// C R
lcd.setCursor(0, 1);
// 111111
// 0123456789012345
// 1023
lcd.print(highThreshold);
what is the 11111 for.
And in typing my question I just worked it out
10, 11, 12...
I suppose the biggest question is why you have spent so much time helping me
I'm sure there are bigger and more rewarding projects out there to tackle than an automatic door for for the 5 Orpington Chickens of Coalgate.
There have been so many Chicken Coop projects on the boards that it was time to put out a complete and finished version.
Now we can say go to this thread:
https://forum.arduino.cc/index.php?topic=674906.0
5 chickens today, 50 tomorrow ![]()
And in typing my question I just worked it out
10, 11, 12...
You are an expert now !
Yes it makes things very easy to format your LCD lines
You can see what it will actually look like and if there will be any column problems.
For example:
// C R
lcd.setCursor(4, 1);
// 111111
// 0123456789012345
// 1023
lcd.print(highThreshold);
Well from my end it has been amazing, certainly made the Lockdown easier to bear.
One thing I note is that when compiling there is a warning
warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
I usually ignore warnings but make this change:
Add const
const char *textStates[] = {"Startup", "GoingUp", "GoingDown", "Morning", "Day",
"Dusk", "Night", "ManState", "AutoState", "UpState",
"DownState", "Moving"
};
It is
time.
Well from my end it has been amazing, certainly made the Lockdown easier to bear.
I am afraid this is a new world.
I will never go on a cruise ship . . . . . .
Dinner time here, and daylight savings has ended so chooks off to bed.
BTW
Since you have some time on your hands go through this thread.
You might find some interesting stuff there.
700+ posts.
https://forum.arduino.cc/index.php?topic=445951.0
Snnnnore . . .
You have a big job in front of you.
Version 7.00 is attached.
To be tested.
ChickenCoopAllenV7.00.ino (39.8 KB)
Its a smaller job now
I just have to build a working model, which is harder than you think as I can't even go and buy a resistor currently but I'm sure I have enough bits around.
Running through the code now.
Upon exit of the Factory Reset it seems to run through the Startup state twice. I haven't tried to find the error yet but will see if I can now.
And if you don't mind I'll put some extra commentary in the file that from a beginner point of view helped me follow it. I'll make notes that I've added denoted as //AP EDIT then can be tidied on the final cut.
Although this project is a chicken door it has potential to control any motor with a settable delay. With minor adjustments it could be a rain sensor, heat sensor, or any other input to drive a motor forward or reverse.
Found the issue with the double reset.
When settingsFlag = true the if statement in void loop is running to creat a timeout.
But in case 12 ResetQuestion if it timesout via the delay with no YES/NO it goes into Automatic but settingsFlag is still true so it times out of the settings when it doesn't need to.
I've added a settingsFlag = false; to the ResetQuestion case to reset the timer.
case ResetQuestion:
{
if (currentMillis - resetQuestionMillis >= resetQuestionDelay)
{
modeSwitchState = Automatic;
digitalWrite(autoManualLED, LEDoff);
lcd.clear();
// C R
lcd.setCursor(0, 0);
// 111111
// 0123456789012345
lcd.print(" Automatic Mode ");
doorStop();
//give some time to read the display
delay(2000);
welcomeMessage();
//AP EDIT - Exiting settings so disable the timer for the settings timeout
settingsFlag = false;
//coming out of manual therefore we need to reset the machine
powerUpFlag = true;
//start the TIMER
powerUpMillis = currentMillis;
//Back to power conditions
mState = Startup;
}
} //END case
break;
You past the test !
Okay, this should be close to the final version.
Cleaned up the code in checkSwitches() quite a bit.
Version 7.10 is attached.
The schematic so everything is in one place.
A better place is here:
//******************
case SetDuskDelay:
{
modeSwitchState = Finished;
//******************
//Handle EEPROM stuff
//if there was a settings change, write the new valuse to EEPROM
if (eepromFlag == true)
{
updateEEPROM();
}
// C R
lcd.setCursor(0, 0);
// 111111
// 0123456789012345
lcd.print(" Factory Reset? ");
// C R
lcd.setCursor(0, 1);
// 111111
// 0123456789012345
lcd.print("Up=YES Down=No ");
//restart TIMER
resetQuestionMillis = currentMillis;
mState = ResetQuestion;
//disable this TIMER
settingsFlag = false; // <-----<<<<<
} //END case
ChickenCoopAllenV7.10.ino (39.3 KB)
The version control still has 7.00, is this the correct file ?
It was 7.10, I forgot to add the notes on the 7.01 changes.
I reattached the file to Post #74, it has updated text added.
EDIT
Added a few comments.
Version 7.20 attached.
EDIT
Updated schematic
ChickenCoopAllenV7.20.ino (39.9 KB)

