Hey guys,
Could you let me know something? I am sending this data over XBee now, and this is my code :
#include <SoftwareSerial.h>
SoftwareSerial XBeeTX(2, 3); // RX, TX
const char data_start = '(';
const char data_format[] = "%c%04X";
char dataStream[6];
volatile byte revolutions;
unsigned int rpm;
unsigned long timeold;
unsigned long k;
void setup()
{
Serial.begin(9600);
XBeeTX.begin(9600);
attachInterrupt(0, rpm_fun, FALLING);
revolutions = 0;
rpm = 0;
timeold = 0;
k = 0;
}
void loop()
{
if (revolutions >= 10) //** Update RPM every 10 counts**
{
k = millis() - timeold;
rpm = 60000/k*revolutions; // **calculate the revolutions per minute
timeold = millis();
revolutions = 0;
sprintf(dataStream, data_format, data_start, rpm);
XBeeTX.print(dataStream);
Serial.println(F("Sent over XBee"));
delay(1000);
}
}
void rpm_fun()
{
revolutions++;
}
My question is when Arduino is at a delay of 1 second, would it enter the void rpm_fun() function and increment the number of revolutions if they are happening?
I have heard XBee requires some delay after transmission, I can make it smaller. But the issue I would still have is : millis() is going to be counted accurately, but at the point where there is a delay() following the the XBee transmission commands the revolutions variable will not be counted (because Arduino won't enter rpm_fun() when it is at the delay() ).
Is it a good idea to do away with the delay() after the XBee transmission since the very condition in the if loop makes sure there is some delay?