Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我无法在类中获得MBED ticker来调用成员方法 我写了下面的基于McC++的程序作为一个实验,为我正在为我的核板微控制器做的更详细的项目: #include "mbed.h" DigitalOut greenLed(PA_5); #include "mbed.h" class TimedLED { public: TimedLED() { Ticker t; t.attach_us(this, &TimedLED::flip, 1000000); } void flip(void) { static int count = 0; greenLed.write(count%2); //-- toggle greenLed count++; } }; int main() { TimedLED flash; while (1); }_C++_C++11_Mbed_Nucleo - Fatal编程技术网

我无法在类中获得MBED ticker来调用成员方法 我写了下面的基于McC++的程序作为一个实验,为我正在为我的核板微控制器做的更详细的项目: #include "mbed.h" DigitalOut greenLed(PA_5); #include "mbed.h" class TimedLED { public: TimedLED() { Ticker t; t.attach_us(this, &TimedLED::flip, 1000000); } void flip(void) { static int count = 0; greenLed.write(count%2); //-- toggle greenLed count++; } }; int main() { TimedLED flash; while (1); }

我无法在类中获得MBED ticker来调用成员方法 我写了下面的基于McC++的程序作为一个实验,为我正在为我的核板微控制器做的更详细的项目: #include "mbed.h" DigitalOut greenLed(PA_5); #include "mbed.h" class TimedLED { public: TimedLED() { Ticker t; t.attach_us(this, &TimedLED::flip, 1000000); } void flip(void) { static int count = 0; greenLed.write(count%2); //-- toggle greenLed count++; } }; int main() { TimedLED flash; while (1); },c++,c++11,mbed,nucleo,C++,C++11,Mbed,Nucleo,我查看的所有引用似乎都表明t.attach_us(this,&TimedLED::flip,1000000)应该每秒调用该方法“flip”,从而导致LED开关。然而,这并没有发生。我看不出有什么问题。我希望有人能帮我弄清楚这件事 我收到以下警告消息,表明此格式已被弃用,但指向文档的链接已断开,因此无法获取更多详细信息: Function "mbed::Ticker::attach_us(T *, M, us_timestamp_t) [with T=TimedLED, M=void(TimedL

我查看的所有引用似乎都表明t.attach_us(this,&TimedLED::flip,1000000)应该每秒调用该方法“flip”,从而导致LED开关。然而,这并没有发生。我看不出有什么问题。我希望有人能帮我弄清楚这件事

我收到以下警告消息,表明此格式已被弃用,但指向文档的链接已断开,因此无法获取更多详细信息:

Function "mbed::Ticker::attach_us(T *, M, us_timestamp_t) [with T=TimedLED, M=void(TimedLED::*)()]" (declared at /extras/mbed_fd96258d940d/drivers/Ticker.h:122) was declared "deprecated" "t.attach_us(this, &TimedLED::flip, 1000000);"

即使它被弃用,它仍然应该工作,不是吗?另外,如果弃用消息是正确的,可能还有一种新的方法来做同样的事情。我在任何地方都找不到替代方法的参考。

您声明
Ticker t
在类中声明变量,它将按预期运行:

class TimedLED
{
    public:
        TimedLED()
        {
            t.attach(callback(this, &TimedLED::flip), 1.0f);
        }

        void flip(void)
        {
            static int count = 0;
            greenLed.write(count%2); //-- toggle greenLed
            count++;
        }

    private:
        Ticker t;
};

还要注意构造函数中的更改,这是在mbed OS 5中附加回调的首选(非不推荐)方法。

您声明
Ticker t
在类中声明变量,它将按预期运行:

class TimedLED
{
    public:
        TimedLED()
        {
            t.attach(callback(this, &TimedLED::flip), 1.0f);
        }

        void flip(void)
        {
            static int count = 0;
            greenLed.write(count%2); //-- toggle greenLed
            count++;
        }

    private:
        Ticker t;
};

还注意构造函数的变化,这是在MBOD OS 5中附加回调的首选方法(C++)。谢谢。因此,我很容易忽略重要的事实,比如T必须在整个类中具有范围时,必须声明为数据成员。谢谢JAN。我在学习MC++的同时,因此,我很容易忽略重要的一点,例如,如果t要在整个类中具有作用域,就必须将其声明为数据成员。