Im new to Arduino and have been trying to use the millis() function for an assignment of mine. I have had a lot of trouble trying to get the millis() function to work but now it seems to be working properly as far as I can tell through the serial viewer but it wont stop my loop once it goes higher than the run time. Im trying to stop my loop after 10 seconds, but it continues going and I feel like it has something to do with my millis().
// Pin 13 is the LED
int led = 13; // pin 13 on the board
int ledOFF = 8; //led off time delay
int ledON = 5; //led on time delay
unsigned long Timer = 0; // store time
int runtime = 10000; // run loop for 10s
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
delay(1000);
}
void loop() {
Timer = millis();
int state = 0;
while(millis() - Timer <= runtime){
Serial.println(Timer);
if(state==0){
digitalWrite(led,LOW);
state = 1;
delay(ledOFF);
}
else{
digitalWrite(led,HIGH);
state = 0;
delay(ledON);
}
}
}