8 years, 10 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

8 years, 10 months ago.

TimeOut is only allowed void functions, so it may take no arguments.

Accepted Answer