arduino library called TimedAction

Hi I'm new and I was trying to use a library that lets me periodically do an action every second and I got an error message saying I didn't define my action in this scope. I studied it and then seeing nothing wrong I tried compiling the sample for TimedAction in which three separate actions are performed periodically and the sample got the same error as my program. "Blink was not defined in this scope" What's up? I know it must be something I don't know about.

Thx John

Please, you must show us your complete sketch. Attach your code using the </> icon on the left side of the posting menu.

See:
http://forum.arduino.cc/index.php?topic=383064.0

...and what library? Link, please?

I'm sorry I didn't respond right away. I wasn't familiar with the forum. If you go to arduino playground and look for TimedAction, and hit search, it will come up with a library called TimedAction that it discusses and gives some examples of its use. It tells you how to install the library and everything. Now if you just highlight the entire example called ThreeExamplesAtOnce and then copy and paste it into the Arduino IDE and make it a new sketch by doing so, assuming you imported the library already, when you go to check it for errors and compile it, it errors out by saying "Blink was not declared in this scope. The place it was defined was in the area prior to the void Setup() which I was of the understanding means it has a global scope. So what am I not understanding. Why doesn't the example compile?

Here's the example. I tried adding #include <arduino.h> but it still got the same error

/*
||
|| @file ThreeExamplesAtOnce.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | This sketch blinks an LED as Blink
|| | sets a led on or off according to serial buffer as PhysicalPixel
|| | prints the ascii table as ASCIITable
|| #
||
*/

#include <TimedAction.h>

//this initializes a TimedAction object that will change the state of an LED every second.
TimedAction blinkAction = TimedAction(1000,blink);
//this initializes a TimedAction object that will change the state of an LED
//according to the serial buffer contents, every 50 milliseconds
TimedAction physicalPixelAction = TimedAction(50,physicalPixel);
//this initializes a TimedAction object that will write tha ascii table to the serial every ten seconds
TimedAction asciiTableAction = TimedAction(10000,asciiTable);

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

void setup(){
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,ledState);
pinMode(physicalPin, OUTPUT);
Serial.begin(9600);
}

void loop(){
blinkAction.check(); //trigger every second
physicalPixelAction.check(); //trigger every 50 millisecond
asciiTableAction.check(); //trigger every 10 second
}

//Examples->Digital->Blink
void blink(){
ledState ? ledState=false : ledState=true;
digitalWrite(ledPin,ledState);
}

//Examples->Digital->PhysicalPixel
void physicalPixel()
{
if (Serial.available()) {
byte val = Serial.read();
if (val == 'H') {
digitalWrite(physicalPin, HIGH);
}
if (val == 'L') {
digitalWrite(physicalPin, LOW);
}
}
}

//Examples->Digital->ASCIITable
void asciiTable()
{
byte number = 33; // first visible character '!' is #33
// print until we have printed last visible character '~' #126 ...
while(number <= 126) {
Serial.print(number, BYTE); // prints value unaltered, first will be '!'

Serial.print(", dec: ");
Serial.print(number); // prints value as string in decimal (base 10)
// Serial.print(number, DEC); // this also works

Serial.print(", hex: ");
Serial.print(number, HEX); // prints value as string in hexadecimal (base 16)

Serial.print(", oct: ");
Serial.print(number, OCT); // prints value as string in octal (base 8)

Serial.print(", bin: ");
Serial.println(number, BIN); // prints value as string in binary (base 2)
// also prints ending line break
number++; // to the next character
}
asciiTableAction.disable();
}

If you go to arduino playground and look for TimedAction, and hit search, it will come up with a library called TimedAction that it discusses and gives some examples of its use

Why should we do that when YOU could have used the link icon and posted a link?

http://playground.arduino.cc/Code/TimedAction

Having downloaded that library, and editing the header file to change WProgram.h to Arduino.h, and fixing one line that tries to print a byte using the BYTE keyword, the example sketch compiles just fine for me.

Yeah I appreciate your time and I apologize for making you click extra clicks. But going to your answer, and believe me when I say I'm sure it is a problem of my own ignorance, I went to the TimedAction.h file that was in the TimedAction library in my Arduino directory under the folder name "libraries" and I could not find the word BYTE anywhere in the file. Then I looked in the example and I did find the BYTE instance and just deleted the entire print statement that used it, and I'm sure that didn't cause the error saying "blink was not defined in this scope. I saw the notice that said WProgram.h was replaced with Arduino.h so I changed that a long time ago relatively, so I did some double checking and searched for any instances of TimedAction.h in my entire computer and it only found the one instance in the library where I installed it. Why would it compile on your computer but not mine? Do you think I need to uninstall and reinstall my entire IDE? I'm running the thing on an XP machine if that matters
John

I am new here. Is it often that old libraries don't work? I am trying to use a library for timing the execution actuators and data recording while using my Controllino which is arduino compatible. I had problems compiling the example that came with the library, so I completely reinstalled the arduino IDE on my windows 7 computer and it still has the same problems. If you download the library code from playground.arduino.cc/Code/TimedAction and copy it to the libraries folder of c:\program files\arduino\libraries and then edit the TimedAction.h file to change the WProgram.h reference to arduino.h, then you would think after restarting the IDE that the examples in that directory would compile without errors. Someone answered my prior post and said that it compiled just fine...It did not for me. Why is that? what am I doing wrong? The error I get is "'blink' not defined in this scope" and a few others as well.
John

There have been changes, and old libraries need often a few little changes.
I did look at the source of that library, and I see "WProgram.h". That should be changed into "Arduino.h" as you noted. The rest is okay.

You should never change the system files in c:\program files.

Do you know where your projects are ? Probably in C:\Users<your-name>\Documents\Arduino
There is a folder "libraries" there for custom libraries. That is where the libraries should go.

Your Arduino system files are no longer original.
Could you remove C:\Program Files\Arduino ? and download the newest Arduino files and install them ?
After that, try to compile a simple example.

If you have errors, please should us the complete output.

The error I get is "'blink' not defined in this scope" and a few others as well.

How about posting the code that you are trying to compile ?

Ok thank you for the advice. I did reinstall the entire Arduino IDE on my windows 7 but then I went right back and installed the library at the c:\program files\arduino\libraries folder, and when I restarted the IDE it had the library available in the IDE so I figured it was OK. I'll try reinstalling again and this time I will look for the other location you just mentioned to install the library in, because I still got that error "'blink' was not declared in this scope". In his example the blink function is actually declared in the main loop() but he is referencing it in the area prior to the setup(). I'll try it tomorrow.
Thx again
John

Never change the system files. Don't change anything at C:\Program Files\Arduino.
Only use that 'libraries' folder next to your projects folder. The Arduino IDE has a library manager (you find many libraries there) and is able to read *.zip file (downloaded from Github) to install libraries.

Perhaps you have installed Arduino twice in two different locations ?

In his example the blink function is actually declared in the main loop()

I find this difficult to believe.

POST YOUR CODE !

Let me see if I got this straight. You downloaded the TimedAction library from a place you want us to hunt from.

You made some changes that you didn't tell us about to the files that you downloaded.

You made some changes to the example that you didn't tell us about.

Then, you tried to compile the example using some version of the IDE (that you didn't tell us) for some Arduino (that you didn't tell us). You got some errors that you tried to paraphrase.

Don't take this wrong, please. But, read what I wrote above, and see if anything occurs to you that you might want to add to your next reply.

Geez you guys sure are giving me a hard time. I posted the code of the example and I told you what library isn't working when you try and compile its example. And you are telling me I am not specific enough. I went to my girlfriend's computer and installed the IDE on a windows 10 computer, then I added the library called TimedAction and then I edited the TimedAction.h file to replace WProgram.h with Arduino.h and then I tried to run the example and it failed to compile the example saying "Blink was not declared in this scope". Period . Nothing else. The IDE I installed is the default one for windows that says 1.6.7. I have a Controllino which is an Atmel 2560 which is Arduino compatible but you can pick any one of the Arduino's and run the example and it fails for me. You can choose any one of the examples that come with the library, there's only two. I studied all the notes available and I learned about having to update the WProgram.h reference with Arduino.h plus one of you guys told me I had to do that. I'm sorry if I am leaving something out. A guy wrote and said he did what I did and it compiled fine for him. I've done it on three different computers XP Windows 7 and Windows 10 and every one of them said "'blink' was not declared in this scope" What am I missing when I tried to compile the example the library provided. Either the guy lied to me and the example doesn't compile or I am losing my marbles. Three different computers and the same result

Try putting a forward declaration to the blink function before it is first used. Maybe the IDE is putting the one it creates for you in the wrong spot.

Here:

#include <TimedAction.h>

void blink();
 
//this initializes a TimedAction object that will change the state of an LED every second.
TimedAction blinkAction                 =       TimedAction(1000,blink);
//this initializes a TimedAction object that will change the state of an LED
//according to the serial buffer contents, every 50 milliseconds
TimedAction physicalPixelAction =       TimedAction(50,physicalPixel);
//this initializes a TimedAction object that will write tha ascii table to the serial every ten seconds
TimedAction asciiTableAction    =       TimedAction(10000,asciiTable);

If that fixes the blink error then you'll probably have to do the same for physicalPixel and asciiTable.

Hiya J5,

I don't think they are giving you a hard time, you didn't read the "how to use the forum" post, so the way you posted your code is causing it to fail. Look:

Serial.print(number, OCT); // prints value as string in octal (base 8)

See the guy with the sunglasses? He's there to make sure it doesn't work. Look at Delta_G's example above. See how his code is in a box? Do that, and it'll make helping you SO much easier!

How do I put the code in a box and by the way its not my code its the example that came with the library? No seriously I am trying to follow direction. I'll go re-read how to use this forum again. The guy with the sunglasses is right next to the word Octal right?

johnnicinco:
How do I put the code in a box and by the way its not my code its the example that came with the library? No seriously I am trying to follow direction. I'll go re-read how to use this forum again. The guy with the sunglasses is right next to the word Octal right?

If you'll read part #7 of How To Use This Forum it will show you exactly how to put your code in code tags to get it in the little box. But you have to actually read it, not just gloss over it. I promise it's in there. Point #7.