'blink' was not declared in this scope need help please

Hi there,
CODE:

//this sketch will blink an LED at pin 13 each second
#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
const byte ledPin = 13;
boolean ledState = false;


void setup(){
  pinMode(ledPin,OUTPUT);
  digitalWrite(ledPin,ledState);
}

void loop(){
  timedAction.check();
  //do something else
}

void blink(){
  ledState ? ledState=false : ledState=true;
  digitalWrite(ledPin,ledState);
}


ERROR:

Arduino: 1.8.16 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

HelloTimedAction:5:44: error: 'blink' was not declared in this scope

 TimedAction timedAction = TimedAction(1000,blink);

                                            ^~~~~

exit status 1

'blink' was not declared in this scope



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

//this sketch will blink an LED at pin 13 each second
#include <TimedAction.h>

//pin / state variables
const byte ledPin = 13;
boolean ledState = false;

void blink(){
  ledState ? ledState=false : ledState=true;
  digitalWrite(ledPin,ledState);
}

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




void setup(){
  pinMode(ledPin,OUTPUT);
  digitalWrite(ledPin,ledState);
}

void loop(){
  timedAction.check();
  //do something else
}


How about now?

ledState=false

Oops

1 Like

Great!
Thank you.

Did you fix the "Oops"?

1 Like

no, but the LED blinking.

Sorry, misread it. Not a oops.
Apologies.

I tried to find the original TimedAction.h-library no success with quoogling.
I found some forks. The xeamples in the forks are rather poor and do not explain in detail how it works and not all functions are provided are explained / demonstrated.

This means the benefits stay in the dark.
Well author of the forks: if you are too lazy to explain the benefits of your library
why did you publish them?

back to programming non-blocking timing
here is a demo-code for non-blocking timing based on a function
The demo-code has quite some explanations at the end on a comment-section

unsigned long DemoTimer      = 0; // variables that are used to store values of function millis()
unsigned long DemoTimerTwo   = 0; // the must be of type unsigned long to work properly all the time
unsigned long DemoTimerThree = 0;
unsigned long DoDelayTimer   = 0;


// helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &expireTime, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();
  if ( currentMillis - expireTime >= TimePeriod )
  {
    expireTime = currentMillis; // set new expireTime
    return true;                // more time than TimePeriod) has elapsed since last time if-condition was true
  }
  else return false;            // not expired
}


void setup() {
  Serial.begin(115200);
  Serial.println("Program started activate Show timestamp in serial monitor");
}


void myDemofunction_1() {
  Serial.println("Huhu ! time for Action A ");
}

void myDemoFuncB() {
  Serial.println("Hi there                  time for Action B ");
}

void my_Demo_function_3() {
  Serial.print("ready now");
  for ( int i = 0; i< 30; i++) {
    Serial.print(".");
  }  
  Serial.println("time for Action C ");
}


void loop() {
  if (  TimePeriodIsOver(DemoTimer, 1000)  ) {
    myDemofunction_1();
  }


  if (  TimePeriodIsOver(DemoTimerTwo, 3000)  ) {
    myDemoFuncB();
  }

  if (  TimePeriodIsOver(DemoTimerThree, 5000)  ) {
    my_Demo_function_3();
  }

  // show the effect of BLOCKING timing caused by function delay()
  if (  TimePeriodIsOver(DoDelayTimer, 20000)  ) {
    Serial.println("every 20 seconds execute delay(5500)... to make all other timers overdue");
    delay(5500);
    Serial.println("as delay(5500 has BLOCKED everything all three timers are overdue");
    Serial.println("which means all three timers fire in the SAME microsecond one after the other ");
  }
}

/*
  the basic principle of non-blocking timing is to check if a defined timeinterval
  has passed by.

  This can be done by using the function millis()
  The function millis()gives back the amount of milliseconds (hence the name millis)
  that have passed by since power-up of the microcontroller.
  It counts up to 2^32 which means reaching the max-value is reached after 49 days.
  There is a calculation-technique that even "rollover" from max to zero is handled
  automatically the right way

  This non-blocking timing needs a timer-variable which is used for taking
  snapshots of time as a comparison-point

  The variable-type for this variable MUST be of type unsigend long
  to make it work reliably all the time

  unsigned long myLcdUpdateTimer;

  now the following construction executes the code inside the if-condition
  only once every two seconds

  if ( TimePeriodIsOver(myLcdUpdateTimer,2000) ) {
     // time for timed action
  }

additionally the code demonstrates how you can code your own functions
and hw to call them.
The names of the functions are a bit lengthy to demonstrate which parts
of the code you can choose freely and to demonstrate where really a relation
between names is and where NO relation between names is

*/

best regards Stefan

1 Like

Thank you.
any other replacement for that library? with even recording?

The search-pattern for quoogling is

Github Arduino your word of interest
https://www.google.de/search?as_q=GitHub+Arduino+Timer

I have done a lot of timing-programming but never used a library for this purpose
always just the function TimePeriodIsOver

1 Like

Thanks [StefanL38],
would you please recommend one which can replace this one with less re code?
Thanks

what do you mean by "less re code"?
and which one is "this" ? You should use clearly to identify names

1 Like

Sorry,
I mean less modification work.

It does make no sense at all to post always just 2 or 3 words like in a whatsApp-chat.
You are working on an informatic project. And what is needed most in an informatic project is information!!!
If you insist in posting too few words to explain in detail what you want
the only answer you will get is a link to "how to get the best out of this forum

well,
I am looking for a replacement of the library, if got one and replaced the existing one, do I need recode the sketch? that's what i mean.

sure you have to re-write the lines of code if the other library is not declared as drop-in-replacement for the other library

you seem to have a wrong picture what writing code means.
It is a bit more work than a quick copy & paste of a few lines of text

1 Like

Thank you.
I searched out one from your link and doing on it.