Sign up ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Can you program a sketch so that if the time is between 1m and 10m then it will reset itself? Reset I found already, it is the if that I don't know.

share|improve this question
    
Are you trying to reset your board every 1 minute? Because when it sees that time is a bit more than 1 minute it will reset. Is that what you mean? – bpinhosilva May 7 at 15:50
    
Are you struggling with if() statements? – portforwardpodcast May 11 at 13:21

1 Answer 1

You can use the timer interrupts. For example:

#define F_CPU   16000000UL
#include <avr/delay.h>
#include <avr/io.h>
#include <string.h>
#include <avr/interrupt.h>
...
ISR(TIMER1_COMPA_vect)
{

  //do something every seconds when interrupt is raised.

}
void setup()
{
/*the following code will setup timer register to generate interrupt
  when 15624 is reached, at a clock frequency of 16 MHz and 1024 prescaler. This means that     every second an interrupt is generated
*/
  cli();          // disable global interrupts
  TCCR1A = 0;     // set entire TCCR1A register to 0
  TCCR1B = 0;     // same for TCCR1B

  // set compare match register to desired timer count:
  OCR1A = 15624;
  // turn on CTC mode:
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler:
  TCCR1B |= (1 << CS10);
  TCCR1B |= (1 << CS12);
  // enable timer compare interrupt:
  TIMSK1 |= (1 << OCIE1A);
  sei();          // enable global interrupts
}

The code works on Arduino Uno. You should calculate the value of OCR1A for your frequency.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.