简体   繁体   English

如何在Arduino上将参数传递给回调函数以进行计时器中断?

[英]How do I pass parameters to a callback function for a timer interrupt on Arduino?

I want a timer interrupt to call a function with a set of parameters on an Arduino. 我希望计时器中断可以在Arduino上调用带有一组参数的函数。 I have looked at the Timer1 library, but it seems unable to be used in a way to pass parameters to the callback function. 我看过Timer1库,但似乎无法以某种方式将参数传递给回调函数。

You can't. 你不能 You'll have to use some sort of global struct to save your current state. 您必须使用某种全局结构来保存当前状态。 When the callback is used, get the data you need from that struct. 使用回调时,从该结构获取所需的数据。

You can wrap your callback into a parameterless function. 您可以将回调包装到无参数函数中。 This wrapper function can pass whatever parameters you want into your function. 该包装函数可以将所需的任何参数传递到函数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM