I don't know if this question is supposed to be in this cateogory but please help. I am trying to develop my first project in which I have an LED, a button and a buzzer, and what I want is that when the button is pressed, the LED blinks for 20 minutes, then the buzzer makes a sound and then the LED becomes like constantly lit for 5 minutes.
For the 20 and the 5 minutes I am using a while loop with millis() but when I am actually like testing it out and having the value of seconds be <= 1200000 (20 minutes in ms), I have a cronometer and it doesn't like stop. I believe this is probably due to the delay(500) i am using for the LED to blink and this probably has an easy fix and method but as I said I am new to this so any help would be appreciated. I am including the code below if you guys want to point out anything else I may be making a mistake with.
int redLED = 3;
int blueLED = 4;
int button = 6;
int buzzer = 5;
int starttime = 0;
int endtime = 0;
void setup() {
Serial.begin(9600); //remove when end
pinMode(A0, INPUT); //potentiometer
pinMode(buzzer, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(button, INPUT_PULLUP);
digitalWrite(redLED, LOW); //initialize all these as off, LEDs as well as we need to see in the void loop which one will be turne on
digitalWrite(blueLED, LOW);
digitalWrite(buzzer, LOW);
}
void loop() {
digitalWrite(redLED, HIGH);
while (digitalRead(button) == HIGH){ //while loop that stops everything until user presses the button to start
}
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
starttime = millis();
endtime = starttime;
while ((endtime - starttime) <=1200000) // do this loop for up to 1000mS = 1S, 20x60x1000=1200
{
digitalWrite(redLED, LOW);
delay(500);
digitalWrite(redLED, HIGH);
delay(500);
endtime = millis();
}
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
starttime = millis();
endtime = starttime;
while ((endtime - starttime) <=120000) // do this loop for up to 1000mS = 1S, 20x60x1000=1200
{
digitalWrite(redLED, HIGH);
endtime = millis();
}
digitalWrite(buzzer, HIGH);
delay(2000);
digitalWrite(buzzer, LOW);
}```