I see the LED is on all the time. I was expecting the LED to blink every 500 ms. What am I doing wrong.
Also when I use after function:
t.after(12000, stopMotorMotion);
I get some compile error as below:
Arduino: 1.8.9 Hourly Build 2019/03/18 11:12 (Mac OS X), Board: "Arduino/Genuino Uno"
/Arduino/codebase/stepperMotor/stepperMotor.ino: In function 'void setup()':
stepperMotor:20:33: error: no matching function for call to 'Timer::after(int, void (&)())'
t.after(12000, stopMotorMotion);
^
In file included from Arduino/codebase/stepperMotor/stepperMotor.ino:2:0:
/Arduino/libraries/Timer-2.1/Timer.h:42:10: note: candidate: int8_t Timer::after(long unsigned int, void (*)(void*), void*)
int8_t after(unsigned long duration, void (*callback)(void*), void* context);
^
/Arduino/libraries/Timer-2.1/Timer.h:42:10: note: candidate expects 3 arguments, 2 provided
exit status 1
no matching function for call to 'Timer::after(int, void (&)())'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
You should declare timestamp as unsigned long, but it doesn't matter because you dont use it for now.
I believe the call to setMotorInMotion(); should be at the end of the setup, otherwise the motor won't stop after 10 seconds.
Since you defined LEDPIN, use it here: t.oscillate(LEDPIN, 10000ul, HIGH);Did you try to reduce the value 10000? Use unsigned long values such as 10000ul. The same for eventimer:
const unsigned long eventTimer = 10000ul; // Run for duration in ms
But I am still getting issue with the after function, which I have mentioned in my post above.
I am not sure, there seems to be some compile error.
One more question, what I'd like to do is blink the LED irrespective of the loop, with oscillate I see that the LED is blinking according to the motor movement as it runs with the loop, which is right.
But as I said what if I have to blink the LED every 500 ms, I tried using every function in Timer library, that too is giving below error:
unsigned long period = 200;
void setup() {
// nothing to do
Serial.begin(9600);
pinMode(LEDPIN, OUTPUT);
t.every(period, flashLED, 100);
}
Error I get:
/Users/udhadv/Documents/Arduino/codebase/stepperMotor/stepperMotor.ino: In function 'void setup()':
/Users/udhadv/Documents/Arduino/codebase/stepperMotor/stepperMotor.ino:20:32: warning: invalid conversion from 'void (*)()' to 'void (*)(void*)' [-fpermissive]
t.every(period, flashLED, 100);
^
In file included from /Users/udhadv/Documents/Arduino/codebase/stepperMotor/stepperMotor.ino:2:0:
/Users/udhadv/Documents/Arduino/libraries/Timer-2.1/Timer.h:40:10: note: initializing argument 2 of 'int8_t Timer::every(long unsigned int, void (*)(void*), void*)'
int8_t every(unsigned long period, void (*callback)(void*), void* context);
^
/Users/udhadv/Documents/Arduino/codebase/stepperMotor/stepperMotor.ino:20:32: warning: invalid conversion from 'int' to 'void*' [-fpermissive]
t.every(period, flashLED, 100);
^
In file included from /Users/udhadv/Documents/Arduino/codebase/stepperMotor/stepperMotor.ino:2:0:
/Users/udhadv/Documents/Arduino/libraries/Timer-2.1/Timer.h:40:10: note: initializing argument 3 of 'int8_t Timer::every(long unsigned int, void (*)(void*), void*)'
int8_t every(unsigned long period, void (*callback)(void*), void* context);
void doAfter()
{
Serial.println("stop the led event");
t.stop(ledEvent);
t.oscillate(13, 500, HIGH, 5);
}
and
int every(long period, callback)
Run the 'callback' every 'period' milliseconds.
Returns the ID of the timer event.
int every(long period, callback, int repeatCount)
Run the 'callback' every 'period' milliseconds for a total of 'repeatCount' times.
Returns the ID of the timer event.
int after(long duration, callback)
Run the 'callback' once after 'period' milliseconds.
Returns the ID of the timer event.
int oscillate(int pin, long period, int startingValue)
Toggle the state of the digital output 'pin' every 'period' milliseconds. The pin's starting value is specified in 'startingValue', which should be HIGH or LOW.
Returns the ID of the timer event.
int oscillate(int pin, long period, int startingValue, int repeatCount)
Toggle the state of the digital output 'pin' every 'period' milliseconds 'repeatCount' times. The pin's starting value is specified in 'startingValue', which should be HIGH or LOW.
Returns the ID of the timer event.
@PaulS : what do you mean :
The signature of the callback function you are trying to use does NOT match the signature that the function MUST have
This says that the 2nd argument should be a pointer to a function that takes a pointer of undefined type and returns nothing. If flashLED() was defined as a function taking a pointer of undefined type and returning nothing, the compiler wouldn't be complaining. Since it is, it is clear that flashLED() is not defined as a function taking a pointer of undefined type returning nothing.
But, since OP can't be bothered posting ALL of his/her code, we'll never know how flashLED() is defined.