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
This code sends the value of 4 sensors every 10 seconds
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
}