Arduino code Millis function help

hello....
i need help with this i need it with Millis function
i need to make the Arduino if i press a button (button1) serial print "high" after 15minitues and every 15 minutes serial print "high" and doing this for 2 hours then stop doing it till i press the button again
and if i press another button (button2)
serial print "high" after 10minitues and every 5 minutes serial print "high" and doing this for 6 hours then stop doing it till i press the button again

doing this using millis not delay

LIKE THIS DELAY BUT MILLIS

if (button1== HIGH) 

{
delay(900000);
Serial.println("high");
delay(900000);
Serial.println("high");
delay(900000);
Serial.println("high");
delay(900000);
Serial.println("high");
delay(900000);
Serial.println("high");
delay(900000);
Serial.println("high");
delay(900000);
Serial.println("high");
delay(900000);

}

if (button2== HIGH) 

{
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);

delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);

delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);

delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
delay(600000);
Serial.println("high");
}

Your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem :wink:

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

Maybe Using millis() for timing. A beginners guide can be of help. And there are probably a few thousand other articles on the web.

Hello

Here is an example, it will print "high" every 5 seconds after releasing the button, during 15 seconds : t1023908.ino - Wokwi Arduino and ESP32 Simulator

I hope not.
Have you ever come across for loops?
That reduces all those repeated commands to just two lines.

What advantage do you see from using millis?

It helps to post ALL your code, as it stands some of it is missing.

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 900000;
const byte BUTTON1 = 13; // You can change
const byte BUTTON2 = 12; // you can change
void setup()
{
Serial.begin(115200);
pinMode(BUTTON1, OUTPUT);
pinMode(BUTTON2, OUTPUT);
startMillis = millis();
}

void loop()
{
currentMillis = millis();
if (currentMillis - startMillis >= period)
{
if (BUTTON1==HIGH) {
digitalWrite(BUTTON1, digitalRead(BUTTON1));
startMillis = currentMillis;
}
if (BUTTON2==HIGH) {
digitalWrite(BUTTON2, digitalRead(BUTTON2));
startMillis = currentMillis;
}
}

}

kodu buraya gir veya yapıştır

:open_mouth: :upside_down_face: :sunglasses:

What do you think this does?

What do you think this does?

He thinks it does
if (digitalRead(BUTTON1) == HIGH)

He thinks it does
digitalWrite(LED1, ! digitalRead(BUTTON1)

But not having declared LED1 as an output, and totally messed up the deceleration BUTTON he is no doubt floundering.

Or maybe he doesn't know what they mean. Nor know that variable names are case sensitive. Like that button1 is not the same variable as BUTTON1

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 900000;
const byte BUTTON1 = 13; // You can change
const byte BUTTON2 = 12; // you can change
void setup()
{
Serial.begin(115200);
pinMode(BUTTON1, OUTPUT);
pinMode(BUTTON2, OUTPUT);
startMillis = millis();
}

void loop()
{
currentMillis = millis();
if (currentMillis - startMillis >= period)
{
if (BUTTON1==HIGH) {
Serial.println(“BUTTON1 high”);
startMillis = currentMillis;
}
if (BUTTON2==HIGH) {
Serial.println(“BUTTON2 high”);
startMillis = currentMillis;
}
}

}

<OT>
Sometimes I admire the audacity of the "do my homework for me" people.
</OT>

abcda you might want to use the code tags <|>

He was told so in post #2 but keeps on ignoring.

@abcda [irony] just keep on posting the same old stuff with the same mistakes and ignoring everything you have been told, you will be fine [\irony]

Alternatively you could start to change the code in response to what you have been told to do and perhaps maybe you might learn something. You might even get more than 0% for your assignment, you never know what you can do if you start to engage your brain.

So as BUTTON1 can not be changed and has the value of 13 how could it not equal HIGH?

You need to read the value of a pin using the digitalRead function. However if BUTTON1 is an output there is no point in reading it.

You should give your variables meaningful names, buttons should be connected to inputs not outputs. Outputs are for things like LEDs, so give the. Appropriate names. Your BUTTON can not be both an input and an output, it can only be one thing.