I need to make use of the TimedAction library for a project. The Arduino website gave an example of how to use this library which you can see here:

#include <TimedAction.h>

//this initializes a TimedAction class that will change the state of an LED every second.
TimedAction timedAction = TimedAction(1000,blink);

//pin / state variables
#define ledPin 13
boolean ledState = false;

void setup(){

void loop(){

void blink(){
ledState ? ledState=false : ledState=true;

This example however does not work, the Arduino ide gives back an error stating that the blink function is declared outside the scope. What is the correct way to implement this?

  • 1
    try moving the void blink() function code to before the timedAction declaration – jsotola Mar 13 '18 at 19:46
  • 1
    Or try adding void blink(); right before TimedAction timedAction = TimedAction(1000,blink); – Gerben Mar 13 '18 at 19:47
  • Ahhh, that's all it took to work! Thank you, I feel like such a fool for not thinking of that! – walkman118 Mar 13 '18 at 19:54
  • 1
    @Gerben care to convert your comment to an answer? Some additional information: The above code did compile in Arduino IDE 1.6.5-r5 and older but with the change to the arduino-builder tool in 1.6.6 the automatic function prototype generation inserts the blink prototype in the wrong place (github.com/arduino/arduino-builder/issues/50). – per1234 Mar 13 '18 at 22:00
  • 1
    Regular C programs require putting the function declaration before the place you are using it. Arduino does this for you. Except in this case, where it doesn’t place it high enough. No need to feel bad. It’s Arduino that is trying to be clever, but fails. – Gerben Mar 14 '18 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.