Thanks I will try and put this information up now!
I have made some progress since I first put this up, after a few weeks of struggling (first time doing this) I had some break throughs.
The problems I am now having are.
I have moved to an LCD screen so I can see what the settings are currently on. but first when I put this together I couldn't change the settings while it was in delay for 12 hours, I think I fixed that problem however now I cant get the motor to turn off.
I understand it is a coding problem not a wiring as I am using Pin 13 so can see the LCD on the board.
I hope this is enough information
I have ended up with this code;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Initialize the LCD object
const int Button = A0; // Runtime button on the shield
// Delay button on the shield
int runtime = 10; // Default runtime in seconds
int delayTime = 12; // Default delay time in hours
unsigned long motorStartTime;
unsigned long motorDuration;
int delayRangeMax = 420;
int delayRangeMin = 405;
bool settingRuntime = true;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Runtime: ");
lcd.print(runtime);
lcd.setCursor(0, 1);
lcd.print("Delay: ");
lcd.print(delayTime);
pinMode(13, OUTPUT);
Serial.begin (9600);
}
void loop() {
int ButtonState = analogRead(Button);
if (ButtonState < 600){
Serial.println ("waiting");
if (ButtonState < 10) {
runtime++;
if (runtime > 60) {
runtime = 1;
}
updateLCD();
delay(200); // Debounce
Serial.println ("Runtime");
}
if (ButtonState > delayRangeMin && ButtonState < delayRangeMax) {
delayTime++;
if (delayTime > 12) {
delayTime = 1;
}
updateLCD();
delay(200); // Debounce
Serial.println ("delay");
}
}
if (millis() - motorStartTime >= motorDuration) {
// Motor action is complete, update settings for the next loop
if (settingRuntime) {
motorDuration = runtime * 1000; // Convert runtime to milliseconds
} else {
motorDuration = delayTime * 3600000; // Convert delayTime to milliseconds
}
digitalWrite(13, HIGH);
motorStartTime = millis();
}
// Let the motor action complete and continue to the next loop
if (millis() - motorStartTime >= motorDuration) {
digitalWrite(13, LOW);
settingRuntime = !settingRuntime; // Toggle between runtime and delay settings
}
}
void updateLCD() {
lcd.setCursor(9, 0);
lcd.print(" "); // Clear previous runtime value
lcd.setCursor(9, 0);
lcd.print(runtime);
lcd.setCursor(7, 1);
lcd.print(" "); // Clear previous delay value
lcd.setCursor(7, 1);
lcd.print(delayTime);
}