Pages: [1]   Go Down
Author Topic: I need a Timer# library, does one exist  (Read 846 times)
0 Members and 1 Guest are viewing this topic.
Buena Vista, CO
Offline Offline
Full Member
***
Karma: 0
Posts: 181
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an Arduino 2560 with a series of sensors.
I want to transmit the values of these sensors
via a rf module ( APC220 ), at approximately
every 10 seconds. I have written a function to do this
when called. I want to use timer 4 to call this function.
The more I search  on the web, the more confused I get.
The timer2 library makes it easy but seems only for timer 2
which as I understand the example, does not extend
to near enough time. Is there a generic timer library
which allows you to use any timer? I looked at the code for timer2
and this is way past my meager knowledge. I would such a library
would be useful to many.
Jim
Logged

8000ft above the average

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


This code sends the value of 4 sensors every 10 seconds


Code:
unsigned long lastTime = 0;

void setup()
{
  Serial.begin(115200);
  Serial.println("Start...");
}

void loop()
{
  if (millis() - lastTime > 10000UL)  // UL means unsigned long
  {
    lastTime += 10000UL;

    float sensor1 = readSensor1();
    float sensor2 = readSensor2();
    float sensor3 = readSensor3();
    float sensor4 = readSensor4();

    Serial.println(sensor1);
    Serial.println(sensor2);
    Serial.println(sensor3);
    Serial.println(sensor4);

    SendRF(sensor1);
    SendRF(sensor2);
    SendRF(sensor3);
    SendRF(sensor4);
  }

  // here you can do something else in theory
}

void SendRF(float value)
{
  // no idea how :)
}

float readSensor1()
{
  // you know this too
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: