Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
C++ 使用arduino变量计算调用变量_C++_Arduino - Fatal编程技术网

C++ 使用arduino变量计算调用变量

C++ 使用arduino变量计算调用变量,c++,arduino,C++,Arduino,如何通过计算调用多个函数或变量 我或多或少需要这样的东西: void 1 () { Order to execute } void 2 () { Order to execute } void 3 () { Order to execute } 我需要一份订单,例如 run = 3221; 我跑了空3,空2​​两次,无效1。 因此,任何要运行的数字组合都不能调用变量。你只调用函数。你可以用它来做你想做的事 void func1() { ... } void func2() { ..

如何通过计算调用多个函数或变量

我或多或少需要这样的东西:

void 1 () {
 Order to execute
}

void 2 () {
 Order to execute
}

void 3 () {
 Order to execute
}
我需要一份订单,例如

run = 3221;
我跑了空3,空2​​两次,无效1。 因此,任何要运行的数字组合都不能调用变量。你只调用函数。你可以用它来做你想做的事

void func1() { ... }
void func2() { ... }
void func3() { ... }

#define MAX_NUMBER_OF_FUNCS 10
typedef void (*MyFunc)();

MyFunc func[MAX_NUMBER_OF_FUNCS] = { func3, func2, func2, func1, NULL };

int main()
{
    ...
    int i = 0;
    while (func[i]) // run func[i] until the value is null
    {
        func[i]();
        i++;
    }
    ...
}
您也可以使用,或

结构函子{ int x; 函子():x(0); void运算符()()常量{my_func();} }; std::function func1=functor();//函数可以包含函子 std::function func2=[](){do_something_else();}//或lambda auto func3=[](){do_something();}; std::function func[函数的最大值]={ func3,func2,func2,[](){other_lambda();},func1,NULL };
struct functor {
  int x;
  functor() : x(0);
  void operator()() const { my_func(); }
};

std::function<void(void)> func1 = functor(); // std::function can contain functor
std::function<void(void)> func2 = []() { do_something_else(); } // or lambda
auto func3 = []() { do_something(); };

std::function<void(void)> func[MAX_NUMBER_OF_FUNCS] = {
    func3, func2, func2, []() { another_lambda(); }, func1, NULL
};