Any syntax in arduino like "setinterval" in Flash?

thank you so much~

never worked with actionscript or flash before but from my understanding setInterval performs a certain action after a set amount of time right?

so if I went:
setInterval( getX(), 1000 );
it would call getX() every 1000 milliseconds right?

this would be the Arduino equivalent:

void getX(){
//whatever you want the function to do
}

then inside your setup:

intervaltime=1000;
currenttime=millis();

and in your main loop:

if(millis()>=currenttime+intervaltime)
{
  getX();
  currenttime=millis();
}

NOTE: this is assuming your loop completes multiple times in a second. This will not work if you want to set an interval at a time smaller than which it takes the program to loop through once. If thats the case you would be looking at interrupts.

thank you so much :wink:

You can also look at MsTimer2 if you want it to happen at a certain interval, and know you'll be busy with other things, or don't want to (or cannot) check otherwise.

http://www.arduino.cc/playground/Main/MsTimer2

!c

If you don't mind the lack of detailed documentation and a precision of one second (setInterval uses 1ms) is ok then there is a library published in this thread that may do what you want: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1217881285/16#16

Here is an example sketch that calls a function at intervals of 5 seconds and 5 minutes.

#include <DateTime.h>
#include <DateTimeAlarms.h>

AlarmID_t myTimer, myTestTimer;

void OnTimer(AlarmID_t Sender){
  // add code here to execute when the timer triggers
    Serial.print("timer triggered,");
 if( Sender == myTimer)
     Serial.println("It was the 5 minute timer");  
}

void setup(){
  Serial.begin(9600);  
  pinMode(13,OUTPUT); // we will flash the LED on and off each second
  myTestTimer = dtAlarms.createTimer( 10, &OnTimer); // create a timer with a period of 10 seconds
  myTimer = dtAlarms.createTimer( AlarmHMS(0, 5, 0), &OnTimer); // create a timer with period: 0 hrs, 5 minutes, 0 seconds
  DateTime.sync(0);   // Start the clock  
}

void  loop(){  
  dtAlarms.delay(1000);  // call dtAlarms.delay instead of delay so the alarms can be serviced
  digitalWrite(13,HIGH);
  dtAlarms.delay(1000);
  digitalWrite(13,HIGH); 
}

By default you can set up 6 different intervals, each calling a different function if you want. The number of intervals is a compile time option if you need more.

The DateTimeAlarms library is use with the DateTime library here: Arduino Playground - DateTime