Using a timer for recalling a function

Hello,

I am pretty new with timers in Arduino. I have heard about timers and read about it.

I want to use a timer to recall a function for each 250ms. (I don’t want to use the delay) But it is hard for me to understand how to archive this. Could you help me out a little bit 'bout how it works and what I have to do?

Kind Regards,

The simplest thing would be to check the timer using millis() in the main loop, and when it is more than 250 mS from the last time, call this function.

http://www.gammon.com.au/millis

Some context would be useful. What else is the Arduino doing? Why does that need to be interrupted every 1/4 of a second? What is the function doing? How accurate does the timing of the calling of that function need to be?

Also: http://www.gammon.com.au/blink

PaulS: Some context would be useful. What else is the Arduino doing? Why does that need to be interrupted every 1/4 of a second? What is the function doing? How accurate does the timing of the calling of that function need to be?

The program is showing a simple menu on a LCD. When a button is pressed, the actual program has to draw something every 250ms. On every tick, new coörs for the drawing have to be calculated and a redraw is needed.

try

int varCount;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly: 
  varCount = varCount++;
  Serial.println(varCount);
  if (varCount == 250){
    function1();
  }
}

void function1()
{
  // Do this every 250ms
  Serial.println("repeat; 250ms.");
  varCount = 0;
}

try

That won't work. That assumes that varCount is increment once per millisecond, which is a lousy assumption.

Not to mention that that increment and assignment statement is silly.

varCount++ is equivalent to varCount = varCount + 1

So, your statement is equivalent to varCount = varCount = varCont + 1 which is clearly silly.

The program is showing a simple menu on a LCD. When a button is pressed, the actual program has to draw something every 250ms. On every tick, new coörs for the drawing have to be calculated and a redraw is needed.

Why does the actual program need to draw something every 250 ms? Why not 240? Or 260? Or 200? Or 300? How accurate does the timing need to be?

If you can’t, or won’t, answer the questions, we can’t help you.