Ok that all makes sense I was declaring the timer too much it was updating each cycle so it would never be correct.
I got it working with the code
unsigned long Timer;
int button = digitalRead(7);
boolean on = true;
void setup()
{
Serial.begin(9600);// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(7, INPUT);
digitalWrite(7, HIGH);
digitalWrite(13, HIGH);
Timer = millis();
}
void loop()
{
if(button == 1)
{
customDelay();
}// put your main code here, to run repeatedly:
}
void customDelay()
{
if (( millis() - Timer) >= 5000)
{
digitalWrite(13, LOW);
}
}
Now I need to reset the timer so when I push the button the delay starts again. Any ideas on how to do that, I tried
unsigned long Timer;
int button = digitalRead(7);
boolean on = true;
void setup()
{
Serial.begin(9600);// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(7, INPUT);
digitalWrite(7, HIGH);
digitalWrite(13, HIGH);
Timer = millis();
}
void loop()
{
if(button == 1)
{
customDelay();
}// put your main code here, to run repeatedly:
if(button == 0)
{
Timer= millis();
}
}
void customDelay()
{
if (( millis() - Timer) >= 5000)
{
digitalWrite(13, LOW);
}
}