Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 5 months ago.
Can't get the Timeout.attach() function to work.
I have a class called "Output".
I want to create a function to set the output high for a set number of seconds. What is wrong with the arguments passed into the Timeout.attach() function?
This code snippet is in the .cpp file.
#include "Output.h"
// Constructor.
Output::Output(PinName pin, bool defaultValue)
{
_digitalOut = new DigitalOut(pin, defaultValue);
}
// Destructor.
Output::~Output()
{
delete _digitalOut;
}
// Set output.
void Output::setOutput(bool value)
{
*_digitalOut = value;
}
// Set output for specified seconds then set back to original value.
void Output::setOutput(bool value, float seconds)
{
// Set output to value.
*_digitalOut = value;
// Set output back to original value after specified time.
_setOutputTimeout.detach();
_setOutputTimeout.attach_us(this, &setOutput(!value), seconds); // Error is on this line
}
1 Answer
10 years, 5 months ago.
TimeOut is only allowed void functions, so it may take no arguments.