RunningAverage library error on compiling

I have been trying to find a way to average data from a sensor. I started with the "smoothing" tutorial but had trouble with the values not averaging but rather constantly adding to themselves. When I couldn't get that to work correctly, I moved to the RunningAverage library. However the RunningAverage library throws an error when I try to compile. To start with Im only trying to follow the example on the page for the RunningAverage library. Specifically the code I am trying to run is:

//
//    FILE: runningAverageTest.pde
//  AUTHOR: Rob Tillaart
//    DATE: 2012-12-30
//
// PUPROSE: show working of runningAverage
//

#include "RunningAverage.h"

RunningAverage myRA(10);
int samples = 0;

void setup(void) 
{
  Serial.begin(115200);
  Serial.println("Demo RunningAverage lib");
  Serial.print("Version: ");
  Serial.println(RUNNINGAVERAGE_LIB_VERSION);
  myRA.clear(); // explicitly start clean
}

void loop(void) 
{
  long rn = random(0, 1000);
  myRA.addValue(rn * 0.001);
  samples++;
  Serial.print("Running Average: ");
  Serial.println(myRA.getAverage(), 3);

  if (samples == 300)
  {
    samples = 0;
    myRA.clear();
  }
  delay(100);
}

I get the following error message:
'RunningAverage' does not name a type
followed in the little terminal window with:

In file included from sketch_may05a.ino:13:
C:\Users\jhanlon\Documents\Arduino\libraries\RunningAverage/RunningAverage.h:1: error: expected unqualified-id before ':' token
C:\Users\jhanlon\Documents\Arduino\libraries\RunningAverage/RunningAverage.h:1: error: expected `)' before ':' token
sketch_may05a:15: error: 'RunningAverage' does not name a type
sketch_may05a.ino: In function 'void setup()':
sketch_may05a:24: error: 'myRA' was not declared in this scope
sketch_may05a.ino: In function 'void loop()':
sketch_may05a:30: error: 'myRA' was not declared in this scope

It seems to me there may be an error in the RunningAverage.h file but I don't know how to troubleshoot that kind of problem as I am completely inexperienced with C++. This is my first post to the forum since I have always been able to do enough googling or forum browsing to get what I want to work with Arduino.
I want this to eventually run on a Mega2560 but can't seem to get past the verify test in the Arduino IDE, so I don't think it is board specific.
By the way, I imported the text verbatim from the arduino webpage into Dev-C++ and saved the .cpp and .h files from there into a folder called "RunningAverage" which is in my arduino libraries folder.
I must have missed something obvious, and greatly appreciate any insight anyone can provide.

This error is usually caused by not having the RunningAverage library installed properly. The library needs to be placed in the libraries subdirectory off where your IDE is stored.

econjack, thank you for the quick response.
I have placed the RunningAverage library in the libraries folder like this:
C:\Program Files (x86)\Arduino\libraries\RunningAverage
There are a bunch of other libraries located here as well and those all seem to work correctly.
When that didn't work I tried placing it in another folder instead:
C:\Users\jhanlon\Documents\Arduino\libraries (this libraries folder is empty)
Is there something else I'm missing?

Hi jershanlon

As a test, what happens if you copy the .h and .cpp files into the same directory as the code you are trying to compile?

If that does not help, try changing the include statement to:

#include <RunningAverage.h>

And did you stop and restart the Arduino IDE after installing the library files?

Regards

Ray

Try what Hackscribble said, but make sure you restart the IDE after copying the library.

Hi there

I've looked at the RunningAverage web page. Just to check, you created the .h and .cpp files by copying and pasting the text from that page?

In the .h file, is your first line "(:source lang=c:)"? Try deleting this and recompile your program.

I included the .h and .cpp files in the same directory and restarted the IDE. Now I've got a whole list of other errors that come up:

sketch_may05b.ino: In function 'void setup()':
sketch_may05b:19: error: 'RUNNINGAVERAGE_LIB_VERSION' was not declared in this scope
Error repainting line range {0,18}:
java.lang.ArrayIndexOutOfBoundsException: -235
	at javax.swing.text.Utilities.drawTabbedText(Utilities.java:132)
	at javax.swing.text.Utilities.drawTabbedText(Utilities.java:89)
	at javax.swing.text.Utilities.drawTabbedText(Utilities.java:67)
	at processing.app.syntax.SyntaxUtilities.paintSyntaxLine(SyntaxUtilities.java:157)
	at processing.app.syntax.TextAreaPainter.paintSyntaxLine(TextAreaPainter.java:647)
	at processing.app.syntax.TextAreaPainter.paintLine(TextAreaPainter.java:606)
	at processing.app.syntax.TextAreaPainter.paint(TextAreaPainter.java:415)
	at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1475)
	at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1406)
	at javax.swing.RepaintManager.paint(RepaintManager.java:1220)
	at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
	at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
	at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "Thread-6" java.lang.ArrayIndexOutOfBoundsException: -45
	at javax.swing.text.Utilities.getTabbedTextWidth(Utilities.java:232)
	at javax.swing.text.Utilities.getTabbedTextWidth(Utilities.java:191)
	at processing.app.syntax.JEditTextArea._offsetToX(JEditTextArea.java:582)
	at processing.app.syntax.JEditTextArea.scrollTo(JEditTextArea.java:464)
	at processing.app.syntax.JEditTextArea.scrollToCaret(JEditTextArea.java:429)
	at processing.app.syntax.JEditTextArea.select(JEditTextArea.java:1215)
	at processing.app.Editor.statusError(Editor.java:2608)
	at processing.app.Editor$DefaultRunHandler.run(Editor.java:1901)
	at java.lang.Thread.run(Thread.java:619)

Now it seems all upset about Java and involving processing (which Im using to make a GUI) and the arduino IDE has hung up.
Am I heading in the right direction?
Thanks again for the suggestions,
Jersh

Sorry, Jersh - my suggestion about putting library files with program clearly caused more trouble!

Delete those files and have a look at my later post about the first line of the .h file. Some of your earlier error messages referred to a problem in line 1 of the .h file, and I have not seen that "(:source lang=c:)" line in a header file before.

Hi, Jersh.

I got the demo program to compile here by copying the .h and .cpp from the web page but deleting the first line of .h and the last lines in both files that said "END OF FILE".

I put the files in a RunningAverage folder in my arduino/libraries folder (the one under where the Arduino program is installed).

Have attached all the files for you to try.

Regards

Ray

RunningAverage.cpp (1.74 KB)

RunningAverage.h (753 Bytes)

RunningAverageDemo.ino (667 Bytes)

I think I've got it working... I think the problem was with both the .cpp and .h files using '#include "RunningAverage.h"' instead of '#include <RunningAverage.h>'. With those changed and the (:language=c:) removed the program compiles.
I need to pick up my kids and make dinner now but I'll upload the code to the arduino with sensors in a couple of hours and test it for real. Im hoping that I can do this for 16 channels without running out of ram on the mega...I'll find out tonight.
Thank you so much for helping me through this. I think it's time I picked a little knowledge in C++.

Hackscribble:
Hi, Jersh.

I got the demo program to compile here by copying the .h and .cpp from the web page but deleting the first line of .h and the last lines in both files that said "END OF FILE".

I put the files in a RunningAverage folder in my arduino/libraries folder (the one under where the Arduino program is installed).

Have attached all the files for you to try.

Regards

Ray

Wow, Thanks! I downloaded the files and will compare to mine.
Cheers!

Just remember that double quotes ("") around an include file name looks for that file in your current working directory where the sketch file is located. If the file is surrounded by angle brackets (<>), it looks in the libraries subdirectory.