Yes. The reason for giving your post a meaningful name, is so when somebody else needs Help with that topic, they are more likely to find this thread, and get the Help they need.
And do us all a favor and read: How To Use This Forum
That said, perhaps this is the Help you seek:
/*****************************************************
* 1 Hour Motor Off Delay
*
* This code assumes Arduino UNO
*
* !!!!!!!!!!!! UNTESTED !!!!!!!!!!!!
******************************************************/
#define switchpin 13 // switch connected to ground and to DP 13
#define motorpin 11 // DP 11 drives motor through tip122
const unsigned long DURATION_HOUR = 3600000; // Number milliseconds in an hour
// Define these here, so if the "logic" changes, you only have to adjust the code in one place [here].
// For instance if you insist on connecting that button to +5, instead of to ground, then
// SW_PRESSED would be 1, instead of 0, etc.
// Also, I guessing at the states of MOTOR_OFF & MOTOR_ON, but, you said TIP122, so it's probably right.
const byte MOTOR_OFF = 0;
const byte MOTOR_ON = 1;
const byte SW_PRESSED = 0;
const byte SW_OPEN = 1;
unsigned long duration = 0;
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
boolean was_switch_pressed = false;
void setup() {
pinMode(switchpin, INPUT_PULLUP);
pinMode(motorpin, OUTPUT);
digitalWrite(motorpin, MOTOR_ON); // I'm assuming... otherwise, what's the point.
previousMillis = millis(); // Capture this here, as an initialization
}
void loop() {
// Listen for switch press, and capture state if so.
// This would better be done with an interrupt, but that would mean the need to
// move the button/switch to pin 2, or pin 3.
if (digitalRead(switchpin) == SW_PRESSED)
{
// No need for a debounce, since this is a trigger event that is only captured
// once [i.e. on the first instance]
was_switch_pressed = true;
}
if (was_switch_pressed)
{
currentMillis = millis();
if(currentMillis - previousMillis > duration)
{
// It's been an hour, so turn the motor off!
digitalWrite(motorpin, MOTOR_OFF);
// Hide in an endless loop. The reasoning here is, the OP said nothing about turning the
// motor back on, so desired functionality is unknown at this point ;)
// Also, it might be a Warm Fuzzy, if an Indicator, of some sort, was presented, to let the
// poor sot, who pressed the button, know that, indeed, something actually happened, and
// the motor is, indeed, destined, after an hour, to actually turn off -- just saying.
while(1) {;}
}
}
else
{
// Place concurrent code here [i.e. code that will be run while waiting for a Motor Turn Off Timeout sequence]
}
}