SimpleTimer Example Will Not Work . . . PLEASE HELP Understanding Error Codes

Ive been googling this problem for hours and cant figure it out. I am still new to programming and arduino. I am trying to use the SimpleTimer library, but cant get it to work. I followed the directions for installing the library at http://playground.arduino.cc/Code/SimpleTimer . I get error messages when I try to verify the following example code given on the playground page

/*
 * SimpleTimerAlarmExample.pde
 *
 * Based on usage example for Time + TimeAlarm libraries
 *
 * A timer is called every 15 seconds
 * Another timer is called once only after 10 seconds
 * A third timer is called 10 times.
 *
 */

#include <SimpleTimer.h>

// There must be one global SimpleTimer object.
// More SimpleTimer objects can be created and run,
// although there is little point in doing so.
SimpleTimer timer;

// function to be called repeatedly
void RepeatTask() {
  Serial.println("15 second timer");        
}

// function to be called just once
void OnceOnlyTask() {
  Serial.println("This timer only triggers once");  
}

// function to be called exactly 10 times
void TenTimesTask() {
  static int k = 0;
  k++;
  Serial.print("called ");
  Serial.print(k);
  Serial.println(" / 10 times.");
}

// print current arduino "uptime" on the serial port
void DigitalClockDisplay() {
  int h,m,s;
  s = millis() / 1000;
  m = s / 60;
  h = s / 3600;
  s = s - m * 60;
  m = m - h * 60;
  Serial.print(h);
  printDigits(m);
  printDigits(s);
  Serial.println();
}

//
// utility function for digital clock display:
// prints preceding colon and leading 0
//
void printDigits(int digits) {
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void setup() {
  Serial.begin(9600);

  // welcome message
  Serial.println("SimpleTimer Example");
  Serial.println("One timer is triggered every 15 seconds");
  Serial.println("Another timer is set to trigger only once after 10 seconds");
  Serial.println("Another timer is set to trigger 10 times");
  Serial.println();

  // timed actions setup
  timer.setInterval(15000, RepeatTask);
  timer.setTimeout(10000, OnceOnlyTask);
  timer.setInterval(1000, DigitalClockDisplay);
  timer.setTimer(1200, TenTimesTask, 10);
}

void loop() {
  // this is where the "polling" occurs
  timer.run();
}

I get the following error codes in the bottom portion of the IDE when I try to verify the code above:

In file included from sketch_sep07a.ino:12:
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: stray '\377' in program
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: stray '\376' in program
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:5: error: stray '@' in program
In file included from sketch_sep07a.ino:12:
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:28:4: error: invalid preprocessing directive #i
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:29:4: error: invalid preprocessing directive #d
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:31:4: error: invalid preprocessing directive #i
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:32:4: error: invalid preprocessing directive #i
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:33:4: error: invalid preprocessing directive #e
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:34:4: error: invalid preprocessing directive #i
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:35:4: error: invalid preprocessing directive #e
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:79: error: missing terminating ' character
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:91: error: missing terminating ' character
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:92: error: missing terminating ' character
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:124:4: error: invalid preprocessing directive #e
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: expected unqualified-id before '/' token
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:8: error: 'y' does not name a type
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:11: error: 'e' does not name a type
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:15: error: 'w' does not name a type
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:21: error: 'i' does not name a type
/Users/myname/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:39: error: 'c' does not name a type
sketch_sep07a:17: error: 'SimpleTimer' does not name a type
sketch_sep07a.ino: In function 'void setup()':
sketch_sep07a:74: error: 'timer' was not declared in this scope
sketch_sep07a.ino: In function 'void loop()':
sketch_sep07a:82: error: 'timer' was not declared in this scope

I think it might have something to do with the library not being properly installed because when I include the library ("#include <SimpleTimer.h>" at the top of the sketch) “SimpleTimer.h” stays black instead of orange. I cant figure out why. I have not found anything on google and have uninstalled it and then reinstalled it several times using the instructions given on the playground page. I am using mac OSX text editor and have saved the files using plain text encoding UTF-8 and UTF-16.

TIA for any help offered.

stays black instead of orange. I cant figure out why.

Did you copy a keywords.txt file? If not, black is what you get.

Thanks Paul.

I found a KEYWORD.TXT file on github and incorporated it into the library. Now the “#include <SimpleTimer.h>” at the top of the sketch changed to orange, but I still get the same error codes in the bottom of the IDE when I try to verify the sketch. :frowning:

You may have several problems which makes finding them more difficult.

The "stray " messages are usually caused because you copied the library from a web page using copy/paste. This can introduce stray characters into the text, even if you can’t see them.

Did you copy/paste or download the file directly ?
Where did you get the library files from ?

It looks like the library is installed correctly because the error messages refer to a file included from your sketch, which means that the compiler found the file. As PaulS suggests you should make sure that you have put all the library files in the library folder.

THANKS UKHeliBob,

I deleted the cut-copy-n-pasted files from the library, replaced them with downloaded files from Github, and it worked. :smiley: THANKS FOR THE ADVICE!!!

can you post a link to the github file you used? I was having the same problem. So I re-saved my files from the GithubFiles I found , but I got this error,

n file included from Coop_1.ino:2:
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:2: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:2: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:2: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:2: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:3: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:3: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:3: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:3: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:4: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:4: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:4: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:4: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:4: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:5: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:6: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:6: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:8: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:8: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:8: error: stray '' in program
In file included from Coop_1.ino:2:
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:14:35: error: invalid suffix "include" on integer constant
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:8: error: stray '' in program
/Users/pixelpusher/Documents/Arduino/libraries/SimpleTimer/SimpleTimer.h:1: error: expected unqualified-id before '{' token

can you post the files you used. I keep getting stray errors? thanks

Any luck getting those files anybody? I’m getting stray errors too, even after I stopped getting the “Does not name a type” errors.

Now I’m getting this:

“In file included from good_bad.ino:1:
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:11: error: stray ‘\302’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:11: error: stray ‘\267’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:242: error: stray ‘@’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:556: error: stray ‘\342’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:556: error: stray ‘\200’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:556: error: stray ‘\246’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: stray ‘#’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: stray ‘#’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: stray ‘#’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: stray ‘#’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: stray ‘#’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: stray ‘#’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: stray ‘#’ in program
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:6: error: expected unqualified-id before ‘<’ token
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: expected constructor, destructor, or type conversion before ‘;’ token
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: expected unqualified-id before numeric constant
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: expected unqualified-id before ‘=’ token
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: expected constructor, destructor, or type conversion before ‘.’ token
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: expected unqualified-id before ‘<’ token
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: expected constructor, destructor, or type conversion before ‘.’ token
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: expected unqualified-id before ‘<’ token
/Users/austinrory/Desktop/Projects/Arduino/libraries/SimpleTimer/SimpleTimer.h:730: error: expected unqualified-id before ‘<’ token”

Hey… I think I loaded the libary correctly. Here’s the sample code from the website I loaded.

#include <SimpleTimer.h>

// the timer object
SimpleTimer timer;

// a function to be executed periodically
void repeatMe() {
    Serial.print("Uptime (s): ");
    Serial.println(millis() / 1000);
}

void setup() {
    Serial.begin(9600);
    timer.setInterval(1000, repeatMe);
}

void loop() {
    timer.run();
}

Here’s the error I get

Arduino: 1.5.6-r2 (Windows 8), Board: "Arduino Uno"

In file included from SimpleTimerSampleCode.ino:1:
C:\Users\Steve\Documents\Arduino\libraries\SimpleTimer/SimpleTimer.h:62: error: 'boolean' does not name a type
C:\Users\Steve\Documents\Arduino\libraries\SimpleTimer/SimpleTimer.h:99: error: 'boolean' does not name a type
SimpleTimerSampleCode:4: error: no matching function for call to 'SimpleTimer::SimpleTimer()'
C:\Users\Steve\Documents\Arduino\libraries\SimpleTimer/SimpleTimer.h:44: note: candidates are: SimpleTimer::SimpleTimer(int)
C:\Users\Steve\Documents\Arduino\libraries\SimpleTimer/SimpleTimer.h:33: note:                 SimpleTimer::SimpleTimer(const SimpleTimer&)
SimpleTimerSampleCode.ino: In function 'void setup()':
SimpleTimerSampleCode:14: error: invalid conversion from 'void (*)()' to 'void (*)(int)'
SimpleTimerSampleCode:14: error: initializing argument 2 of 'int SimpleTimer::setInterval(long int, void (*)(int))'

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

It highlights the SimpleTimer Timer light in orange.
Can anyone help me figure out why it won’t compile. I’d like to use the timer in my latest project.

Can anyone help me figure out why it won’t compile.

The first error message tells you:

SimpleTimerSampleCode:4: error: no matching function for call to ‘SimpleTimer::SimpleTimer()’
C:\Users\Steve\Documents\Arduino\libraries\SimpleTimer/SimpleTimer.h:44: note: candidates are: SimpleTimer::SimpleTimer(int)
C:\Users\Steve\Documents\Arduino\libraries\SimpleTimer/SimpleTimer.h:33: note: SimpleTimer::SimpleTimer(const SimpleTimer&)

The messages mean that the SimpleTimer class does not have a no-argument constructor. Why do you think it does?

It is also telling you that the callback function is supposed to take an int. Why doesn’t your callback function take an int?