run the loop 10 times per hour

i have a simple program to blink 2 led,how to run the loop 10 times per hour and shut off?

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin1 =  13;      // the number of the LED pin
const int ledPin2 =  10;
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  
  buttonState = digitalRead(buttonPin);

  
  if (buttonState == HIGH) 

   { 
    delay(1000);
    digitalWrite(ledPin1, HIGH);
    delay(1000);
    digitalWrite(ledPin1, LOW);
    delay(1000);
    digitalWrite(ledPin2, HIGH);
    delay(4000);
    digitalWrite(ledPin2, LOW);
    delay(1000);
   }
}

Hi,

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

What does your code do/not do?

Thanks… Tom… :slight_smile:

Tell us more.

How is the switch wired?

BTW delay(1000); Is one second.

.

sorry,i had edited

sorry for bad english.

blink led1 1 second and off, than,blink led2 4 seconds and off

it's a circle,i want this circle run 10 times every 6 minutes after press button once.

Add blink without delay to check for an hour passing, and then a for loop to run the sequence 10 times:

loop(){
currentTime = millis(); // capture the "time"
if ((currentTime - previousTime) >= oneHour){ // has an hour passed?
previousTime = previousTime + oneHour; // set up for next hour
for (x=0; x<10; x=x+1){ // cycle thru 10 times
// your LED sequence
} // end loop of 10
} // end of time check
} // end of loop

all time elements are unsigned long
oneHour = 1000ms/Sec * 60 Sec/min * 60 min/hr = 3600000UL

How is your push button switch wired?

LarryD: How is your push button switch wired? [/q

LarryD: How is your push button switch wired?

like this https://www.arduino.cc/en/Tutorial/Button

How are your LEDs wired?

.

CrossRoads:
Add blink without delay to check for an hour passing, and then a for loop to run the sequence 10 times:

loop(){

currentTime = millis(); // capture the “time”
if ((currentTime - previousTime) >= oneHour){ // has an hour passed?
previousTime = previousTime + oneHour; // set up for next hour
for (x=0; x<10; x=x+1){ // cycle thru 10 times
// your LED sequence
} // end loop of 10
} // end of time check
} // end of loop



all time elements are unsigned long
oneHour = 1000ms/Sec * 60 Sec/min * 60 min/hr = 3600000UL
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin1 =  13;      // the number of the LED pin
const int ledPin2 =  10;
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) 
  currentTime = millis(); // capture the "time"
  if ((currentTime - previousTime) >= oneHour){ // has an hour passed?
       previousTime = previousTime + oneHour; // set up for next hour
       for (x=0; x<10; x=x+1)
       { // cycle thru 10 times
          { 
           delay(1000);
           digitalWrite(ledPin1, HIGH);
           delay(1000);
           digitalWrite(ledPin1, LOW);
           delay(1000);
           digitalWrite(ledPin2, HIGH);
           delay(4000);
           digitalWrite(ledPin2, LOW);
           delay(1000);
          }
        } // end loop of 10
     } // end of time check
} // end of loop
}

i add in ,but it show

‘currentTime’ was not declared in this scope

how to fix?

LarryD: How are your LEDs wired?

.

like this,and 2 leds, 10 and 13 https://www.arduino.cc/en/Tutorial/Blink

You have to declare all the variables I called out in the pre-setup area of your code.