Can anyone help me find the average of 5 rpm values? Please..
void loop()
{
delay(1000);
detachInterrupt(0);
rpm = 8570/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
Serial.println(rpm);
attachInterrupt(0, RPM, FALLING);
}
Can anyone help me find the average of 5 rpm values? Please..
void loop()
{
delay(1000);
detachInterrupt(0);
rpm = 8570/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
Serial.println(rpm);
attachInterrupt(0, RPM, FALLING);
}
Throw away that code and try writing your own.
Most probably millis()-timeold is zero in every loop() iteration. See BlinkWithoutDelay to do something in regular time intervals, here getting the rpm count.
Sum up e.g. 5 rpm values and divide by 5 to get the average.
Please follow the advice on posting code given in Read this before posting a programming question
In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless
If the code exceeds the 9000 character inline limit then attach it to a post
UKHeliBob:
Please follow the advice on posting code given in Read this before posting a programming questionIn particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless
If the code exceeds the 9000 character inline limit then attach it to a post
Done! Any idea about taking the average??
Thank you for adding the code tags
I bet that the code does not compile for a number of reasons. Where did you get it from ?
Given a means of measuring RPM and a pencil and paper how would you do it ?
You could take 10 readings, writing down each as you go, sum the readings and divide by 10
Or you could take readings and add them to a total as you get them, then after 10 readings divide the total by 10
The program could use either method but will depend on reading the RPM periodically. Have you got the hardware and software to read the RPM ?
UKHeliBob:
Thank you for adding the code tagsI bet that the code does not compile for a number of reasons. Where did you get it from ?
Given a means of measuring RPM and a pencil and paper how would you do it ?
You could take 10 readings, writing down each as you go, sum the readings and divide by 10Or you could take readings and add them to a total as you get them, then after 10 readings divide the total by 10
The program could use either method but will depend on reading the RPM periodically. Have you got the hardware and software to read the RPM ?
Yes....actually I'm just trying to figure out taking the average right now and not the actual rpm values..
I'm just trying to figure out taking the average right now and not the actual rpm values..
OK, here are 10 values
162 12 232 18 9 300 0 87 99 123
Work out the average on paper using one or both of the methods that I suggested. It will help you write a program to do it because the program will need to execute the same steps
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.