Go Down

Topic: I need a Timer# library, does one exist (Read 906 times) previous topic - next topic

alfiesty

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
8000ft above the average

robtillaart


This code sends the value of 4 sensors every 10 seconds


Code: [Select]

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
}
Rob Tillaart

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy